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()