numpy.gcd

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

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

参数
X1,X2类数组

值的数组。如果 x1.shape != x2.shape ,它们必须可以广播到公共形状(成为输出的形状)。

返回
yndarray或scalar

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

参见

lcm

最小公倍数

实例

>>> 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])