Python numpy.lcm() Examples
The following are 30 code examples for showing how to use numpy.lcm(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: recruit Author: Frank-qlu File: test_umath.py License: 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 2
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_umath.py License: 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 3
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_umath.py License: 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
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_umath.py License: 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 5
Project: pySINDy Author: luckystarufo File: test_umath.py License: 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
Project: coffeegrindsize Author: jgagneastro File: test_umath.py License: 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 7
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: test_umath.py License: 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
Project: twitter-stock-recommendation Author: alvarobartt File: test_umath.py License: 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
Project: recruit Author: Frank-qlu File: test_umath.py License: 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 10
Project: recruit Author: Frank-qlu File: test_umath.py License: 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 11
Project: recruit Author: Frank-qlu File: test_umath.py License: 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 12
Project: recruit Author: Frank-qlu File: test_umath.py License: 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 13
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_umath.py License: 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 14
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_umath.py License: 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 15
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_umath.py License: 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 16
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_umath.py License: 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 17
Project: trax Author: google File: math_ops.py License: 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 18
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_umath.py License: 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 19
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_umath.py License: 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 20
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_umath.py License: 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 21
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_umath.py License: 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 22
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_umath.py License: 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 23
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_umath.py License: 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 24
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_umath.py License: 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 25
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_umath.py License: 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 26
Project: pySINDy Author: luckystarufo File: test_umath.py License: 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 27
Project: pySINDy Author: luckystarufo File: test_umath.py License: 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 28
Project: pySINDy Author: luckystarufo File: test_umath.py License: 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 29
Project: pySINDy Author: luckystarufo File: test_umath.py License: 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 30
Project: coffeegrindsize Author: jgagneastro File: test_umath.py License: 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)