Python numpy.polynomial.polynomial.polymul() Examples
The following are 30
code examples of numpy.polynomial.polynomial.polymul().
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.polynomial.polynomial
, or try the search function
.
Example #1
Source File: test_polynomial.py From recruit with Apache License 2.0 | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #2
Source File: test_polynomial.py From keras-lambda with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #3
Source File: test_polynomial.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #4
Source File: test_polynomial.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #5
Source File: test_polynomial.py From coffeegrindsize with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #6
Source File: test_polynomial.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #7
Source File: test_polynomial.py From ImageFusion with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #8
Source File: test_polynomial.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #9
Source File: test_polynomial.py From pySINDy with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #10
Source File: test_polynomial.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #11
Source File: test_polynomial.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #12
Source File: test_polynomial.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #13
Source File: test_polynomial.py From Computable with MIT License | 6 votes |
def test_polydiv(self) : # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5) : for j in range(5) : msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #14
Source File: test_polynomial.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #15
Source File: operations.py From PySyft with Apache License 2.0 | 6 votes |
def poly_mul(op1, op2, poly_mod): """return multiplication of two polynomials with result % t(polynomial modulus)""" # For non same size polynomials we have to shift the polynomials because numpy consider right # side as lower order of polynomial and we consider right side as heigher order. if len(op1) != len(op2): if len(op1) > len(op2): op2 = op2 + [0] * (len(op1) - len(op2)) else: op1 = op1 + [0] * (len(op2) - len(op1)) poly_len = poly_mod poly_mod = np.array([1] + [0] * (poly_len - 1) + [1]) result = ( poly.polydiv( poly.polymul(np.array(op1, dtype="object"), np.array(op2, dtype="object")), poly_mod, )[1] ).tolist() if len(result) != poly_len: result += [0] * (poly_len - len(result)) return [round(x) for x in result]
Example #16
Source File: test_polynomial.py From vnpy_crypto with MIT License | 6 votes |
def test_polydiv(self): # check zero division assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) quo, rem = poly.polydiv([2, 2], [2]) assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) assert_equal(res, tgt, err_msg=msg)
Example #17
Source File: test_polynomial.py From recruit with Apache License 2.0 | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #18
Source File: test_polynomial.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #19
Source File: test_polynomial.py From keras-lambda with MIT License | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #20
Source File: test_polynomial.py From recruit with Apache License 2.0 | 5 votes |
def test_polypow(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) c = np.arange(i + 1) tgt = reduce(poly.polymul, [c]*j, np.array([1])) res = poly.polypow(c, j) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #21
Source File: test_polynomial.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #22
Source File: test_polynomial.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #23
Source File: test_polynomial.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #24
Source File: test_polynomial.py From coffeegrindsize with MIT License | 5 votes |
def test_polypow(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) c = np.arange(i + 1) tgt = reduce(poly.polymul, [c]*j, np.array([1])) res = poly.polypow(c, j) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #25
Source File: test_polynomial.py From coffeegrindsize with MIT License | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #26
Source File: test_polynomial.py From vnpy_crypto with MIT License | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #27
Source File: test_polynomial.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #28
Source File: test_polynomial.py From ImageFusion with MIT License | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #29
Source File: test_polynomial.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_polymul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
Example #30
Source File: operations.py From PySyft with Apache License 2.0 | 5 votes |
def poly_mul_mod(op1, op2, coeff_mod, poly_mod): """Multiply two polynomials and modulo every coefficient with coeff_mod. Args: op1 (list): First Polynomail (Multiplicand). op2 (list): Second Polynomail (Multiplier). Returns: A list with polynomial coefficients. """ # For non same size polynomials we have to shift the polynomials because numpy consider right # side as lower order of polynomial and we consider right side as heigher order. if len(op1) != poly_mod: op1 += [0] * (poly_mod - len(op1)) if len(op2) != poly_mod: op2 += [0] * (poly_mod - len(op2)) poly_len = poly_mod poly_mod = np.array([1] + [0] * (poly_len - 1) + [1]) result = ( poly.polydiv( poly.polymul(np.array(op1, dtype="object"), np.array(op2, dtype="object")) % coeff_mod, poly_mod, )[1] % coeff_mod ).tolist() if len(result) != poly_len: result += [0] * (poly_len - len(result)) return [round(x) for x in result]