當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.lcm方法代碼示例

本文整理匯總了Python中numpy.lcm方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.lcm方法的具體用法?Python numpy.lcm怎麽用?Python numpy.lcm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.lcm方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _test_lcm_inner

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import lcm [as 別名]
def _test_lcm_inner(self, dtype):
        # basic use
        a = np.array([12, 120], dtype=dtype)
        b = np.array([20, 200], dtype=dtype)
        assert_equal(np.lcm(a, b), [60, 600])

        if not issubclass(dtype, np.unsignedinteger):
            # negatives are ignored
            a = np.array([12, -12,  12, -12], dtype=dtype)
            b = np.array([20,  20, -20, -20], dtype=dtype)
            assert_equal(np.lcm(a, b), [60]*4)

        # reduce
        a = np.array([3, 12, 20], dtype=dtype)
        assert_equal(np.lcm.reduce([3, 12, 20]), 60)

        # broadcasting, and a test including 0
        a = np.arange(6).astype(dtype)
        b = 20
        assert_equal(np.lcm(a, b), [0, 20, 20, 60, 20, 20]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:test_umath.py

示例2: test_lcm_overflow

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import lcm [as 別名]
def test_lcm_overflow(self):
        # verify that we don't overflow when a*b does overflow
        big = np.int32(np.iinfo(np.int32).max // 11)
        a = 2*big
        b = 5*big
        assert_equal(np.lcm(a, b), 10*big) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_umath.py

示例3: test_gcd_overflow

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import lcm [as 別名]
def test_gcd_overflow(self):
        for dtype in (np.int32, np.int64):
            # verify that we don't overflow when taking abs(x)
            # not relevant for lcm, where the result is unrepresentable anyway
            a = dtype(np.iinfo(dtype).min)  # negative power of two
            q = -(a // 4)
            assert_equal(np.gcd(a,  q*3), q)
            assert_equal(np.gcd(a, -q*3), q) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_umath.py

示例4: test_decimal

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import lcm [as 別名]
def test_decimal(self):
        from decimal import Decimal
        a = np.array([1,  1, -1, -1]) * Decimal('0.20')
        b = np.array([1, -1,  1, -1]) * Decimal('0.12')

        assert_equal(np.gcd(a, b), 4*[Decimal('0.04')])
        assert_equal(np.lcm(a, b), 4*[Decimal('0.60')]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_umath.py

示例5: test_float

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import lcm [as 別名]
def test_float(self):
        # not well-defined on float due to rounding errors
        assert_raises(TypeError, np.gcd, 0.3, 0.4)
        assert_raises(TypeError, np.lcm, 0.3, 0.4) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:test_umath.py

示例6: lcm

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import lcm [as 別名]
def lcm(x1, x2):
  def f(x1, x2):
    d = _tf_gcd(x1, x2)
    # Same as the `x2_safe` trick above
    d_safe = tf.where(d == 0, tf.constant(1, d.dtype), d)
    return tf.where(d == 0, tf.constant(0, d.dtype),
                    tf.math.abs(x1 * x2) // d_safe)
  return _bin_op(f, x1, x2) 
開發者ID:google,項目名稱:trax,代碼行數:10,代碼來源:math_ops.py


注:本文中的numpy.lcm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。