python interpolate.interp1d_索引错误scipy.interpolate.interp1d「建议收藏」

python interpolate.interp1d_索引错误scipy.interpolate.interp1d「建议收藏」我试图得到一个三次样条函数scipy.interpolate.interp1d功能。我试图让documentationpage上的示例正常工作,但每当我运行它时,都会出现以下错误:plt.plot(x,y,’o’,xnew,f(xnew),’-‘,xnew,f2(xnew),’–‘)File”/Library/Python/2.7/site-packages/scipy-0.12.0…

大家好,又见面了,我是你们的朋友全栈君。

我试图得到一个三次样条函数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()

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/135815.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号