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()
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/135815.html原文链接:https://javaforall.cn
相关文章
- 快速了解 OJ 判题系统如何在python中使用?
- jupyter和python的关系_jupyter notebook和python
- 解决python中导出的pdf不能编辑问题
- 纯 Python 搭建全文搜索引擎
- Python求逆矩阵_3x3下三角矩阵求逆矩阵
- python计算双色球数字概率_python绘制双色球走势图
- Python || 皖事通安康码截图信息简易识别采集
- 【python】分苹果
- 如何设置python的环境变量_anaconda环境变量手动设置
- Python开发者必知的13个Python GUI库
- 修改python的pip源为国内源[通俗易懂]
- python win32api messagebox_如何在Python中使用Win32 API?
- python 制作淘宝秒杀脚本
- 一个精壮的代购骗子被我用Python彻底征服了
- Python文本情感分析_Python数据分析实战
- Python继续霸榜,SQL写得溜,面试或许能加分
- Python 学生信息管理系统——文章中源码100%真实有效—–如何将类、初始化属性、模块、循环判断、静态方法等一系列知识点结合起来做一个项目「建议收藏」
- 不止短信!教你用 Python 发送告警通知到微信
- Python DB-API 规范及 MySQL Connector/Python 实现
- Python-drf前戏38.2-前端Vue02