flopscope.numpy.gcd
fnp.gcd(*args, **kwargs)[flopscope source][numpy source]
Returns the greatest common divisor of ``|x1|`` and ``|x2|``
Adapted from NumPy docs np.gcd
Cost
16×
Flopscope Context
Element-wise greatest common divisor.
Returns the greatest common divisor of |x1| and |x2|
Parameters
- x1, x2:array_like, int
Arrays of values. If
x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
Returns
- y:ndarray or scalar
The greatest common divisor of the absolute value of the inputs This is a scalar if both
x1andx2are scalars.
See also
- we.flops.lcm The lowest common multiple
Examples
>>> import flopscope.numpy as fnp
>>> flops.gcd(12, 20)
4
>>> flops.gcd.reduce([15, 25, 35])
5
>>> flops.gcd(flops.arange(6), 20)
array([20, 1, 2, 1, 4, 5])