【发布时间】:2016-07-06 21:56:15
【问题描述】:
我想做一些分段三次 Hermite 插值并得到多项式的 根。 (我曾经在 matlab 中执行此操作,但现在想在 python 3.4 中实现此操作)。
我尝试使用 scipy PchipInterpolator。插值可以,但是当我尝试检索根时出现此错误...
我现在被困在这里,找不到任何解决方法。这是一个简单的代码,重现了我所做的事情以及确切的错误消息...
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()
错误信息:
numpy : 1.10.1
scipy :0.17.1
Traceback (most recent call last):
File "test.py", line 11, in <module>
print(f.roots()) # this produces an error !
File "/usr/local/lib/python3.4/dist-packages/scipy/interpolate/_monotone.py", line 105, in roots
return (PPoly.from_bernstein_basis(self._bpoly)).roots()
AttributeError: 'PchipInterpolator' object has no attribute '_bpoly'
Process finished with exit code 1
但是 scipy 文档说:“roots() 返回插值函数的根。”
我在这里错过了什么?
【问题讨论】:
标签: python matlab scipy interpolation