當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy lcm用法及代碼示例

本文簡要介紹 python 語言中 numpy.lcm 的用法。

用法:

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

返回 |x1||x2| 的最小公倍數

參數

x1, x2 數組樣,int

值數組。如果 x1.shape != x2.shape ,它們必須可以廣播到一個公共形狀(成為輸出的形狀)。

返回

y ndarray 或標量

輸入絕對值的最小公倍數 如果 x1 和 x2 都是標量,則這是一個標量。

例子

>>> np.lcm(12, 20)
60
>>> np.lcm.reduce([3, 12, 20])
60
>>> np.lcm.reduce([40, 12, 20])
120
>>> np.lcm(np.arange(6), 20)
array([ 0, 20, 20, 60, 20, 20])

相關用法


注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.lcm。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。