0
立方体和线性插值我想通过np.linspace()
命令从-2.5 to 2.0
插8个数据点,并充分理解这些数字应为非负,但然而,当我运行我的代码,我得到它说raise ValueError("x and y arrays must be equal in length along " ValueError: x and y arrays must be equal in length along interpolation axis.
错误这里是我的代码:1D在python
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
X = np.linspace(-2.5, 2.0, num=8, endpoint=True)
Y = np.linspace(1, 44, num=44, endpoint=True)
f = interp1d(X,Y)
f2 = interp1d(X, Y, kind='cubic')
Xnew = np.linspace(-2.5, 2.0, num=44, endpoint=True)
plt.plot(X, Y, 'o', Xnew, f(Xnew), Xnew, f2(Xnew), '--' )
plt.legend(['data', 'linear', 'cubic'], loc='best')
plt.show()