我想做一些分段三次hermite插值,得到多项式的根。(我以前在matlab中执行此操作,但现在希望在Python3.4中实现)。
我试着用scipy pchip插值器。插值是可以的,但当我试图检索根时,我遇到了这个错误…
我现在被困在这里,找不到任何解决办法。这是一个简单的代码,复制我所做的和准确的错误信息。。。在
import matplotlib.pyplot as plt
from scipy import interpolate, __version__
import numpy as np
print('numpy : ' + np.__version__)
print('scipy :' + __version__)
x = np.arange(10)
y = [1., 1., 3., 2., 1., 1., 1.5, 2., 8., 1.]
f = interpolate.PchipInterpolator(x, y, axis=0, extrapolate=None)
print(f.roots()) # this produces an error !
xnew = np.arange(0, 9, 0.1)
ynew = f(xnew) # use interpolation function returned by `PchipInterpolator`
plt.plot(x, y, 'o', xnew, ynew, '-')
plt.show()
错误消息:
^{pr2}$但是scipy文档说:“roots()返回插值函数的根。”
我错过了什么?在
这是西皮的虫子。在
(请在https://github.com/scipy/scipy/issues上报告)
作为解决方法,您可以手动转换为功率基准:
EDIT:如果使用这个解决方法,并且您有非默认的
axis
,那么最好检查在转换时是否处理了轴。如果不是,也请报告。在相关问题 更多 >
编程相关推荐