scipy.interpolate.pchip出错了

时间:2017-08-06 23:16:00

标签: scipy interpolation

我正在尝试运行以下代码:

ValueError                                Traceback (most recent call last)
<ipython-input-61-256eb8fb78c2> in <module>()
      4 curve = interpolate.pchip(x,y)
      5 ys = curve(xs)
----> 6 dys = curve.derivative(xs)#Construct a new piecewise polynomial 
representing the derivative.
      7 pl.plot(xs,ys,label=u'pchip')
      8 pl.plot(xs,dys,label=u'1 class diff')

C:\Program Files\Anaconda3\lib\site-packages\scipy\interpolate\interpolate.py in derivative(self, nu)
   1377 
   1378         """
-> 1379         if nu < 0:
   1380             return self.antiderivative(-nu)
   1381 

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

但是出现了这样的错误:

|

我使用的系统是Windows + Python3.5 + Anaconda + Jupyter笔记本。

谢谢。

1 个答案:

答案 0 :(得分:1)

我解释docs的方式,而不是:

dys = curve.derivative(xs)

你应该这样做:

deriv = curve.derivative()
dys = deriv(xs)

# alternative
# dys = curve.derivative()(xs)

whiches给出:

enter image description here