gcd#

ivy.gcd(x1, x2, /, *, out=None)[source]#

Return the greatest common divisor of |x1| and |x2|.

Parameters:
  • x1 (Union[Array, NativeArray, int, list, tuple]) – First array-like input.

  • x2 (Union[Array, NativeArray, int, list, tuple]) – Second array-input.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – Element-wise gcd of |x1| and |x2|.

Examples

>>> x1 = ivy.array([1, 2, 3])
>>> x2 = ivy.array([4, 5, 6])
>>> ivy.gcd(x1, x2)
ivy.array([1.,    1.,   3.])
>>> x1 = ivy.array([1, 2, 3])
>>> ivy.gcd(x1, 10)
ivy.array([1.,   2.,  1.])
Array.gcd(self, x2, /, *, out=None)[source]#

ivy.Array instance method variant of ivy.gcd. This method simply wraps the function, and so the docstring for ivy.gcd also applies to this method with minimal changes.

Parameters:
  • self (Union[Array, int, list, tuple]) – First array-like input.

  • x2 (Union[Array, int, list, tuple]) – Second array-like input

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – Element-wise gcd of |x1| and |x2|.

Examples

>>> x1 = ivy.array([1, 2, 3])
>>> x2 = ivy.array([4, 5, 6])
>>> x1.gcd(x2)
ivy.array([1.,    1.,   3.])
>>> x1 = ivy.array([1, 2, 3])
>>> x1.gcd(10)
ivy.array([1.,   2.,  1.])
Container.gcd(self, x2, /, *, out=None)[source]#

ivy.Container instance method variant of ivy.gcd. This method simply wraps the function, and so the docstring for ivy.gcd also applies to this method with minimal changes.

Parameters:
  • self (Container) – first input container with array-like items.

  • x2 (Container) – second input container with array-like items.

  • out (Optional[Container], default: None) – optional output container, for writing the result to.

Return type:

Container

Returns:

ret – Container including arrays with element-wise gcd of input arrays.

Examples

>>> x1 = ivy.Container(a=ivy.array([1, 2, 3]),                               b=ivy.array([1, 2, 3]))
>>> x2 = ivy.Container(a=ivy.array([5, 6, 7]),                               b=10)
>>> x1.gcd(x2)
{
    a: ivy.array([1.,  1.,  3.])
    b: ivy.array([1., 2., 1.])
}