Python numpy.lcm() Examples
The following are 30
code examples of numpy.lcm().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_umath.py From pySINDy with MIT License | 6 votes |
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])
Example #2
Source File: test_umath.py From recruit with Apache License 2.0 | 6 votes |
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])
Example #3
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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])
Example #4
Source File: test_umath.py From twitter-stock-recommendation with MIT License | 6 votes |
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])
Example #5
Source File: test_umath.py From coffeegrindsize with MIT License | 6 votes |
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])
Example #6
Source File: test_umath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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])
Example #7
Source File: test_umath.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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])
Example #8
Source File: test_umath.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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])
Example #9
Source File: test_umath.py From pySINDy with MIT License | 5 votes |
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')])
Example #10
Source File: test_umath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: test_umath.py From pySINDy with MIT License | 5 votes |
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)
Example #12
Source File: test_umath.py From coffeegrindsize with MIT License | 5 votes |
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)
Example #13
Source File: test_umath.py From coffeegrindsize with MIT License | 5 votes |
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)
Example #14
Source File: test_umath.py From coffeegrindsize with MIT License | 5 votes |
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')])
Example #15
Source File: test_umath.py From coffeegrindsize with MIT License | 5 votes |
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)
Example #16
Source File: test_umath.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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)
Example #17
Source File: test_umath.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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)
Example #18
Source File: test_umath.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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')])
Example #19
Source File: test_umath.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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)
Example #20
Source File: test_umath.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #21
Source File: test_umath.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #22
Source File: test_umath.py From twitter-stock-recommendation with MIT License | 5 votes |
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')])
Example #23
Source File: test_umath.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #24
Source File: math_ops.py From trax with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: test_umath.py From recruit with Apache License 2.0 | 5 votes |
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)
Example #26
Source File: test_umath.py From recruit with Apache License 2.0 | 5 votes |
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)
Example #27
Source File: test_umath.py From recruit with Apache License 2.0 | 5 votes |
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')])
Example #28
Source File: test_umath.py From recruit with Apache License 2.0 | 5 votes |
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)
Example #29
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
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)
Example #30
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
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)