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


Python numpy.poly方法代碼示例

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


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

示例1: test_poly

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def test_poly(self):
        assert_array_almost_equal(np.poly([3, -np.sqrt(2), np.sqrt(2)]),
                                  [1, -3, -2, 6])

        # From matlab docs
        A = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
        assert_array_almost_equal(np.poly(A), [1, -6, -72, -27])

        # Should produce real output for perfect conjugates
        assert_(np.isrealobj(np.poly([+1.082j, +2.613j, -2.613j, -1.082j])))
        assert_(np.isrealobj(np.poly([0+1j, -0+-1j, 1+2j,
                                      1-2j, 1.+3.5j, 1-3.5j])))
        assert_(np.isrealobj(np.poly([1j, -1j, 1+2j, 1-2j, 1+3j, 1-3.j])))
        assert_(np.isrealobj(np.poly([1j, -1j, 1+2j, 1-2j])))
        assert_(np.isrealobj(np.poly([1j, -1j, 2j, -2j])))
        assert_(np.isrealobj(np.poly([1j, -1j])))
        assert_(np.isrealobj(np.poly([1, -1])))

        assert_(np.iscomplexobj(np.poly([1j, -1.0000001j])))

        np.random.seed(42)
        a = np.random.randn(100) + 1j*np.random.randn(100)
        assert_(np.isrealobj(np.poly(np.concatenate((a, np.conjugate(a)))))) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_polynomial.py

示例2: poly2ac

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def poly2ac(poly, efinal):
    """ Convert prediction filter polynomial to autocorrelation sequence

    :param array poly: the AR parameters
    :param efinal: an estimate of the final error
    :return: the autocorrelation  sequence in complex format.

    .. doctest::

        >>> from numpy import array
        >>> from spectrum import poly2ac
        >>> poly = [ 1. ,  0.38 , -0.05]
        >>> efinal = 4.1895
        >>> poly2ac(poly, efinal)
        array([ 5.00+0.j, -2.00+0.j,  1.01-0.j])

    """
    results = rlevinson(poly, efinal)
    return results[0] 
開發者ID:cokelaer,項目名稱:spectrum,代碼行數:21,代碼來源:linear_prediction.py

示例3: _gener

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def _gener(delta2, m, mu, symbolic):
    # Computes the lambda_q from the article, eq. (9).
    lmbdas2 = []
    for q in range(1, m + 1):
        if not lmbdas2:
            # https://github.com/numpy/numpy/issues/16152
            coeffs = [1]
        else:
            coeffs = numpy.poly(lmbdas2)

        a0 = [c * mu(2 * (q - k) + 2, symbolic) for k, c in enumerate(coeffs)]
        a1 = [c * mu(2 * (q - k), symbolic) for k, c in enumerate(coeffs)]
        prod_ = prod([1 - lmbda2 / delta2 for lmbda2 in lmbdas2])
        a = sum(a0) - mu(2, symbolic) ** (q + 1) / mu(0, symbolic) ** q * prod_
        b = sum(a1) - mu(2, symbolic) ** (q + 1) / mu(0, symbolic) ** q * prod_ / delta2
        lmbdas2.append(a / b)
    return lmbdas2 
開發者ID:nschloe,項目名稱:quadpy,代碼行數:19,代碼來源:_cools_haegemans.py

示例4: lsf2poly

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def lsf2poly(L):

    # always use double precision 
    dtype = L.dtype
    L = L.astype(np.float64)

    order = len(L)
    Q = L[::2]
    P = L[1::2]
    poles_P = np.r_[np.exp(1j*P),np.exp(-1j*P)]
    poles_Q = np.r_[np.exp(1j*Q),np.exp(-1j*Q)]
    
    P = np.poly(poles_P)
    Q = np.poly(poles_Q)
    
    # convolve from scipy.signal
    # only supports even orders
    P = convolve(P, np.array([1.0, -1.0]))
    Q = convolve(Q, np.array([1.0, 1.0]))
    
    a = 0.5*(P+Q)
 
    a = a[:-1]

    return a.astype(dtype) 
開發者ID:ljuvela,項目名稱:ResGAN,代碼行數:27,代碼來源:get_mfcc.py

示例5: test_minreal_2

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def test_minreal_2(self):
        """This one gave a problem, due to poly([]) giving simply 1
        instead of numpy.array([1])"""
        s = TransferFunction([1, 0], [1])
        G = 6205/(s*(s**2 + 13*s + 1281))
        Heq = G.feedback(1)
        H1 = 1/(s+5)
        H2a = Heq/H1
        H2b = H2a.minreal()
        hr = 6205/(s**2+8*s+1241)
        np.testing.assert_array_almost_equal(H2b.num[0][0], hr.num[0][0])
        np.testing.assert_array_almost_equal(H2b.den[0][0], hr.den[0][0])
        np.testing.assert_equal(H2b.dt, hr.dt) 
開發者ID:python-control,項目名稱:python-control,代碼行數:15,代碼來源:xferfcn_test.py

示例6: test_objects

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def test_objects(self):
        from decimal import Decimal
        p = np.poly1d([Decimal('4.0'), Decimal('3.0'), Decimal('2.0')])
        p2 = p * Decimal('1.333333333333333')
        assert_(p2[1] == Decimal("3.9999999999999990"))
        p2 = p.deriv()
        assert_(p2[1] == Decimal('8.0'))
        p2 = p.integ()
        assert_(p2[3] == Decimal("1.333333333333333333333333333"))
        assert_(p2[2] == Decimal('1.5'))
        assert_(np.issubdtype(p2.coeffs.dtype, np.object_))
        p = np.poly([Decimal(1), Decimal(2)])
        assert_equal(np.poly([Decimal(1), Decimal(2)]),
                     [1, Decimal(-3), Decimal(2)]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:16,代碼來源:test_polynomial.py

示例7: test_zero_dims

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def test_zero_dims(self):
        try:
            np.poly(np.zeros((0, 0)))
        except ValueError:
            pass 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_polynomial.py

示例8: test_poly_int_overflow

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def test_poly_int_overflow(self):
        """
        Regression test for gh-5096.
        """
        v = np.arange(1, 21)
        assert_almost_equal(np.poly(v), np.poly(np.diag(v))) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_polynomial.py

示例9: test_simple

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import poly [as 別名]
def test_simple(self):
        z_r = np.array([0.5, -0.5])
        p_r = np.array([1.j / np.sqrt(2), -1.j / np.sqrt(2)])
        # Sort the zeros/poles so that we don't fail the test if the order
        # changes
        z_r.sort()
        p_r.sort()
        b = np.poly(z_r)
        a = np.poly(p_r)

        z, p, k = tf2zpk(b, a)
        z.sort()
        p.sort()
        assert_array_almost_equal(z, z_r)
        assert_array_almost_equal(p, p_r) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:17,代碼來源:test_filter_design.py


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