scipy插值interpolation

>>> from scipy.interpolate import interp1d
#
interp1d表示1维插值
>>>
>>> x = np.linspace(0, 10, num=11, endpoint=True) >>> y = np.cos(-x**2/9.0) >>> f = interp1d(x, y) >>> f2 = interp1d(x, y, kind='cubic')
#
kind='cubic' 省去kind参数 默认为线性插值
>>>
>>> xnew = np.linspace(0, 10, num=41, endpoint=True)
#xnew表示插值之后,画图,选取的画图点数,再用线将这些点连起来 >>> 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()
../_images/interpolate-1.png

插值的方法 通过kind 导入;

f2 = interp1d(x, y, kind='cubic') 返回一个插值后的函数

>>> from scipy.interpolate import interp1d
>>>
>>> x = np.linspace(0, 10, num=11, endpoint=True) >>> y = np.cos(-x**2/9.0) >>> f1 = interp1d(x, y, kind='nearest') >>> f2 = interp1d(x, y, kind='previous') >>> f3 = interp1d(x, y, kind='next') 
>>>
>>> xnew = np.linspace(0, 10, num=1001, endpoint=True) >>> import matplotlib.pyplot as plt >>> plt.plot(x, y, 'o') >>> plt.plot(xnew, f1(xnew), '-', xnew, f2(xnew), '--', xnew, f3(xnew), ':') >>> plt.legend(['data', 'nearest', 'previous', 'next'], loc='best') >>> plt.show() 
../_images/interpolate-2.png
 

转载于:https://www.cnblogs.com/ggzhangxiaochao/p/9083343.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值