def test_as_series(self): # check exceptions assert_raises(ValueError, pu.as_series, [[]]) assert_raises(ValueError, pu.as_series, [[[1, 2]]]) assert_raises(ValueError, pu.as_series, [[1], ['a']]) # check common types types = ['i', 'd', 'O'] for i in range(len(types)): for j in range(i): ci = np.ones(1, types[i]) cj = np.ones(1, types[j]) [resi, resj] = pu.as_series([ci, cj]) assert_(resi.dtype.char == resj.dtype.char) assert_(resj.dtype.char == types[i])
def test_as_series(self) : # check exceptions assert_raises(ValueError, pu.as_series, [[]]) assert_raises(ValueError, pu.as_series, [[[1,2]]]) assert_raises(ValueError, pu.as_series, [[1],['a']]) # check common types types = ['i', 'd', 'O'] for i in range(len(types)) : for j in range(i) : ci = np.ones(1, types[i]) cj = np.ones(1, types[j]) [resi, resj] = pu.as_series([ci, cj]) assert_(resi.dtype.char == resj.dtype.char) assert_(resj.dtype.char == types[i])
def polydiv(c1, c2): """ Divide one polynomial by another. Returns the quotient-with-remainder of two polynomials `c1` / `c2`. The arguments are sequences of coefficients, from lowest order term to highest, e.g., [1,2,3] represents ``1 + 2*x + 3*x**2``. Parameters ---------- c1, c2 : array_like 1-D arrays of polynomial coefficients ordered from low to high. Returns ------- [quo, rem] : ndarrays Of coefficient series representing the quotient and remainder. See Also -------- polyadd, polysub, polymulx, polymul, polypow Examples -------- >>> from numpy.polynomial import polynomial as P >>> c1 = (1,2,3) >>> c2 = (3,2,1) >>> P.polydiv(c1,c2) (array([3.]), array([-8., -4.])) >>> P.polydiv(c2,c1) (array([ 0.33333333]), array([ 2.66666667, 1.33333333])) # may vary """ # c1, c2 are trimmed copies [c1, c2] = pu.as_series([c1, c2]) if c2[-1] == 0: raise ZeroDivisionError() # note: this is more efficient than `pu._div(polymul, c1, c2)` lc1 = len(c1) lc2 = len(c2) if lc1 < lc2: return c1[:1] * 0, c1 elif lc2 == 1: return c1 / c2[-1], c1[:1] * 0 else: dlen = lc1 - lc2 scl = c2[-1] c2 = c2[:-1] / scl i = dlen j = lc1 - 1 while i >= 0: c1[i:j] -= c2 * c1[j] i -= 1 j -= 1 return c1[j + 1:] / scl, pu.trimseq(c1[:j + 1])
def as_series(alist, trim=True): from numpy.polynomial.polyutils import as_series return as_series(alist, trim)
def as_series(alist, trim=True) : from numpy.polynomial.polyutils import as_series return as_series(alist, trim)
def __mul__(self, c1, c2): # c1, c2 are trimmed copies [c1, c2] = pu.as_series([c1, c2]) ret = np.convolve(c1, c2) return pu.trimseq(ret)