numpy.gcd#

numpy.gcd(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'gcd'>#

返回 |x1||x2| 的最大公约数

参数:
x1, x2array_like, int

值数组。如果 x1.shape != x2.shape,它们必须能够广播到共同的形状(这将成为输出的形状)。

返回:
yndarray 或 标量

输入绝对值的最大公约数。如果 x1x2 都是标量,则这是一个标量。

另请参阅

lcm

最小公倍数

示例

>>> import numpy as np
>>> np.gcd(12, 20)
4
>>> np.gcd.reduce([15, 25, 35])
5
>>> np.gcd(np.arange(6), 20)
array([20,  1,  2,  1,  4,  5])