我尝试使用西比插值.interp2d,但我有一个问题。这是我的代码:import scipy.interpolate as itpimport numpy as npimport matplotlib.pyplot as pltz_srtrm = 100 * np.random.rand(4,4)x_srtrm = np.arange(0,4)y_srtrm = np.arange(0,4)I = itp.interp2d(x_srtrm,y_srtrm,z_srtrm,kind='cubic') xi = np.linspace(0,4,100) yi = np.linspace(0,4,100) Z = I(xi,yi) zx = np.arange(0,100)zy = np.arange(0,100)I_inv = itp.interp2d(zx,zy,Z,kind='cubic') xj = np.linspace(0,100,4) yj = np.linspace(0,100,4) z = I_inv(xj,yj)fig = plt.figure()ax1 = fig.add_subplot(1,3,1)ax1.imshow(z_srtrm)ax2 = fig.add_subplot(1,3,2)ax2.imshow(Z)ax3 = fig.add_subplot(1,3,3)ax3.imshow(z)plt.show()通常,z_srtm应等于 z,但事实并非如此。你能解释一下为什么吗?提前感谢您。
1 回答
慕无忌1623718
TA贡献1744条经验 获得超4个赞
原因是由于工作原理而产生的逐个错误:np.arange
>>> np.arange(0, 10)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
您需要进行两项更改。首先,从 0 到 3,因此在上采样时需要保持这一点:x_srtrmy_srtrm
I = itp.interp2d(x_srtrm, y_srtrm, z_srtrm, kind='cubic')
xi = np.linspace(0, 3, 100)
yi = np.linspace(0, 3, 100)
Z = I(xi, yi)
其次,从 0 到 99,因此在缩减采样时需要考虑它:zxzy
I_inv = itp.interp2d(zx, zy, Z, kind='cubic')
xj = np.linspace(0, 99, 4)
yj = np.linspace(0, 99, 4)
z = I_inv(xj, yj)
添加回答
举报
0/150
提交
取消