欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

python的scipy实现插值的示例代码

时间:2021-06-26 08:47:00|栏目:Python代码|点击:

插值对于一些时间序列的问题可能比较有用。

Show the code directly:

import numpy as np
from matplotlib import pyplot as plt
from scipy.interpolate import interp1d
 
x=np.linspace(0,10*np.pi,num=20)
y=np.sin(x)
f1=interp1d(x,y,kind='linear')#线性插值
f2=interp1d(x,y,kind='cubic')#三次样条插值
x_pred=np.linspace(0,10*np.pi,num=1000)
y1=f1(x_pred)
y2=f2(x_pred)
plt.plot(x_pred,y1,'r',label='linear')
plt.plot(x_pred,y2,'b--',label='cubic')
plt.legend()
plt.show()

官网上有更详细的参数使用:https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp1d.html

上一篇:详解pandas DataFrame的查询方法(loc,iloc,at,iat,ix的用法和区别)

栏    目:Python代码

下一篇:在Django的上下文中设置变量的方法

本文标题:python的scipy实现插值的示例代码

本文地址:http://www.codeinn.net/misctech/148388.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有