具体代码如下所示:
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
插值对于一些时间序列的问题可能比较有用。
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'