请问有人能告诉我numpy中Chebyshev函数的区别吗?
numpy.polynomial.Chebyshev.basis(deg)
并且scipy对Chebyshev的解释 -
scipy.special.chebyt(deg)
这将会是非常有帮助的。感谢您的提前帮助!
请问有人能告诉我numpy中Chebyshev函数的区别吗?
numpy.polynomial.Chebyshev.basis(deg)
并且scipy对Chebyshev的解释 -
scipy.special.chebyt(deg)
这将会是非常有帮助的。感谢您的提前帮助!
scipy.special
多项式函数使用了 np.poly1d
,该方法已过时且容易出错 - 特别是它将 x0
的索引存储在 poly.coeffs[-1]
中。
numpy.polynomial.Chebyshev
将系数按更合理的顺序存储,并保持其基础形式,可以提高精度。您可以使用 cast
方法进行转换。>>> from numpy.polynomial import Chebyshev, Polynomial
# note loss of precision
>>> sc_che = scipy.special.chebyt(4); sc_che
poly1d([ 8.000000e+00, 0.000000e+00, -8.000000e+00, 8.881784e-16, 1.000000e+00])
# using the numpy functions - note that the result is just in terms of basis 4
>>> np_che = Chebyshev.basis(4); np_che
Chebyshev([ 0., 0., 0., 0., 1.], [-1., 1.], [-1., 1.])
# converting to a standard polynomial - note that these store the
# coefficient of x^i in .coeffs[i] - so are reversed when compared to above
>>> Polynomial.cast(np_che)
Polynomial([ 1., 0., -8., 0., 8.], [-1., 1.], [-1., 1.])