基于python的分段三次hermite插值器的根

基于python的分段三次hermite插值器的根,python,matlab,scipy,interpolation,Python,Matlab,Scipy,Interpolation,我想做一些分段三次hermite插值,得到多项式的根。(我以前在matlab中这样做,但现在想在python 3.4中实现这一点)。 我试着使用scipy PchipInterpolator。插值是可以的,但是当我试图检索根时,我得到了这个错误… 我现在被困在这里,找不到任何解决办法。这里是一个简单的代码复制我所做的和确切的错误消息 import matplotlib.pyplot as plt from scipy import interpolate, __version__ import

我想做一些分段三次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
numpy:1.10.1
scipy:0.17.1
回溯(最近一次呼叫最后一次):
文件“test.py”,第11行,在
打印(f.roots())#这会产生错误!
文件“/usr/local/lib/python3.4/dist packages/scipy/interpolate/_monotone.py”,第105行,以根为单位
返回(PPoly.from_bernstein_basis(self._bpoly)).roots()
AttributeError:'PchipInterpolator'对象没有属性'\u bpoly'
进程已完成,退出代码为1
然而,scipy文档说:“roots()返回插值函数的根。”


我在这里遗漏了什么?

这是scipy中的一个bug

(请报告)

作为一种解决方法,您可以手动转换为功率基准:

In [1]: from scipy.interpolate import pchip

In [2]: import numpy as np

In [3]: x = np.arange(10)

In [4]: y = [1., 1., 3., 2., 1., 1., 1.5, 2., 8., 1.]

In [5]: s = pchip(x, y)

In [6]: from scipy.interpolate import PPoly

In [7]: pp = PPoly.from
PPoly.from_bernstein_basis  PPoly.from_spline

In [7]: pp = PPoly.from_bernstein_basis(s)

In [8]: pp.roots()
Out[8]: array([  9.07179677,  22.92820323])
编辑:如果确实使用此解决方法,并且您有非默认的
,则最好在转换时检查轴是否已处理。如果不是,请也报告