gcd(x1, x2, out=None, **kwargs)

Returns the greatest common divisor of |x1| and |x2|

  • x2 (x1,) – The arrays for computing greatest common divisor. If x1.shape != x2.shape, they must be broadcastable to a common shape (which may be the shape of one or the other).

  • out (ndarray or None, optional) – A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.


y – The greatest common divisor of the absolute value of the inputs This is a scalar if both x1 and x2 are scalars.

Return type

ndarray or scalar

See also


The lowest common multiple


>>> np.gcd(12, 20)
>>> np.gcd(np.arange(6, dtype=int), 20)
array([20,  1,  2,  1,  4,  5], dtype=int64)