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


Python hermite.hermfit方法代碼示例

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


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

示例1: test_hermfit

# 需要導入模塊: from numpy.polynomial import hermite [as 別名]
# 或者: from numpy.polynomial.hermite import hermfit [as 別名]
def test_hermfit(self) :
        def f(x) :
            return x*(x - 1)*(x - 2)

        # Test exceptions
        assert_raises(ValueError, herm.hermfit, [1],    [1],     -1)
        assert_raises(TypeError,  herm.hermfit, [[1]],  [1],      0)
        assert_raises(TypeError,  herm.hermfit, [],     [1],      0)
        assert_raises(TypeError,  herm.hermfit, [1],    [[[1]]],  0)
        assert_raises(TypeError,  herm.hermfit, [1, 2], [1],      0)
        assert_raises(TypeError,  herm.hermfit, [1],    [1, 2],   0)
        assert_raises(TypeError,  herm.hermfit, [1],    [1],   0, w=[[1]])
        assert_raises(TypeError,  herm.hermfit, [1],    [1],   0, w=[1, 1])

        # Test fit
        x = np.linspace(0, 2)
        y = f(x)
        #
        coef3 = herm.hermfit(x, y, 3)
        assert_equal(len(coef3), 4)
        assert_almost_equal(herm.hermval(x, coef3), y)
        #
        coef4 = herm.hermfit(x, y, 4)
        assert_equal(len(coef4), 5)
        assert_almost_equal(herm.hermval(x, coef4), y)
        #
        coef2d = herm.hermfit(x, np.array([y, y]).T, 3)
        assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
        # test weighting
        w = np.zeros_like(x)
        yw = y.copy()
        w[1::2] = 1
        y[0::2] = 0
        wcoef3 = herm.hermfit(x, yw, 3, w=w)
        assert_almost_equal(wcoef3, coef3)
        #
        wcoef2d = herm.hermfit(x, np.array([yw, yw]).T, 3, w=w)
        assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
        # test scaling with complex values x points whose square
        # is zero when summed.
        x = [1, 1j, -1, -1j]
        assert_almost_equal(herm.hermfit(x, x, 1), [0, .5]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:44,代碼來源:test_hermite.py

示例2: test_hermfit

# 需要導入模塊: from numpy.polynomial import hermite [as 別名]
# 或者: from numpy.polynomial.hermite import hermfit [as 別名]
def test_hermfit(self):
        def f(x):
            return x*(x - 1)*(x - 2)

        # Test exceptions
        assert_raises(ValueError, herm.hermfit, [1], [1], -1)
        assert_raises(TypeError, herm.hermfit, [[1]], [1], 0)
        assert_raises(TypeError, herm.hermfit, [], [1], 0)
        assert_raises(TypeError, herm.hermfit, [1], [[[1]]], 0)
        assert_raises(TypeError, herm.hermfit, [1, 2], [1], 0)
        assert_raises(TypeError, herm.hermfit, [1], [1, 2], 0)
        assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[[1]])
        assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[1, 1])

        # Test fit
        x = np.linspace(0, 2)
        y = f(x)
        #
        coef3 = herm.hermfit(x, y, 3)
        assert_equal(len(coef3), 4)
        assert_almost_equal(herm.hermval(x, coef3), y)
        #
        coef4 = herm.hermfit(x, y, 4)
        assert_equal(len(coef4), 5)
        assert_almost_equal(herm.hermval(x, coef4), y)
        #
        coef2d = herm.hermfit(x, np.array([y, y]).T, 3)
        assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
        # test weighting
        w = np.zeros_like(x)
        yw = y.copy()
        w[1::2] = 1
        y[0::2] = 0
        wcoef3 = herm.hermfit(x, yw, 3, w=w)
        assert_almost_equal(wcoef3, coef3)
        #
        wcoef2d = herm.hermfit(x, np.array([yw, yw]).T, 3, w=w)
        assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
        # test scaling with complex values x points whose square
        # is zero when summed.
        x = [1, 1j, -1, -1j]
        assert_almost_equal(herm.hermfit(x, x, 1), [0, .5]) 
開發者ID:pfchai,項目名稱:ImageFusion,代碼行數:44,代碼來源:test_hermite.py


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