pythonscipy样条插值函数⼤全(interpolate⾥interpld函数)scipy样条插值
linspace函数pythonscipy样条插值
1、样条插值法是⼀种以可变样条来作出⼀条经过⼀系列点的光滑曲线的数学⽅法。插值样条是由⼀些多项式组成的,每⼀个多项式都是由相邻的两个数据点决定的,这样,任意的两个相邻的多项式以及它们的导数(不包括仇阶导数)在连接点处都是连续的。 连接点的光滑与连续是样条插值和前边分段多项式插值的主要区别。
2、在Scipy⾥可以⽤scipy.interpolate模块下的interpld函数 实现样条插值。 SciPy的0.14.0版本⾥样条插值⽅式有:'linear','zero', 'slinear', 'quadratic'(2次), 'cubic'(3次), 4, 5等。
3、scipy多次样条插值的应⽤格式如下所⽰:
import numpy as np, matplotlib.pyplot as plt
from scipy.interpolate import interpld #导⼊scipy⾥interpolate模块中的interpld插值模块
x= np.array([0, 1, 2, 3, 4, 5, 6, 7])
y= np.array([3, 4, 3.5, 2, 1, 1.5, 1.25, 0.9]) #离散点的分布
xx = np.linspace(x.min(), x.max(), 100) #新的插值区间及其点的个数
plt.scatter(x, y) #散点图
#for n in ['linear','zero', 'slinear', 'quadratic', 'cubic', 4, 5]: #python scipy⾥⾯的各种插值函数
f = interp1d(x, y,kind="cubic") #编辑插值函数格式
ynew=f(xx) #通过相应的插值函数求得新的函数点
plt.plot(xx,ynew,"g") #输出新的函数点的图像
plt.show()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。