python interpolate.interp1d_索引错误scipy.interpolate.interp1d

我试图得到一个三次样条函数scipy.interpolate.interp1d功能。我试图让documentation page上的示例正常工作,但每当我运行它时,都会出现以下错误:plt.plot(x,y,'o',xnew,f(xnew),'-', xnew, f2(xnew),'--') File

"/Library/Python/2.7/site-packages/scipy-0.12.0.dev_ddd617d_20120920-py2.7-macosx-10.8-x86_64.egg/scipy/interpolate/interpolate.py",

line 396, in call

y_new = self._call(x_new) File "/Library/Python/2.7/site-packages/scipy-0.12.0.dev_ddd617d_20120920-py2.7-macosx-10.8-x86_64.egg/scipy/interpolate/interpolate.py",

line 372, in _call_spline

result = spleval(self._spline,x_new.ravel()) File "/Library/Python/2.7/site-packages/scipy-0.12.0.dev_ddd617d_20120920-py2.7-macosx-10.8-x86_64.egg/scipy/interpolate/interpolate.py",

line 835, in spleval

res[sl] = _fitpack._bspleval(xx,xj,cvals[sl],k,deriv) IndexError: too many indices

所以,它适用于线性插值,但不适用于立方。我可能犯了一些愚蠢的错误,但我不知道出了什么问题。下面是我使用的示例代码:import numpy as np

from scipy.interpolate import interp1d

x = np.linspace(0, 10, 40)

y = np.cos(-x**2/8.0)

f = interp1d(x, y)

f2 = interp1d(x, y, kind='cubic')

xnew = np.linspace(0, 10, 10)

import matplotlib.pyplot as plt

plt.plot(x,y,'o',xnew,f(xnew),'-', xnew, f2(xnew),'--')

plt.legend(['data', 'linear', 'cubic'], loc='best')

plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值