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