【发布时间】:2020-12-26 15:30:31
【问题描述】:
例如,我有一个索引数组
ax = [0, 0.2, 2] #start from index 0: python
和矩阵I
I=
10 20 30 40 50
10 20 30 40 50
10 20 30 40 50
10 20 30 40 50
10 20 30 40 50
在 MATLAB 中,通过运行此代码
[gx, gy] = meshgrid([1,1.2,3], [1,1.2,3]);
I = [10:10:50];
I = vertcat(I,I,I,I,I)
SI = interp2(I,gx,gy,'bilinear');
生成的SI 是
SI =
10 12 30
10 12 30
10 12 30
我尝试在 Python 中使用 NumPy 进行相同的插值。我首先按行插入,然后按列插入
import numpy as np
ax = np.array([0.0, 0.2, 2.0])
ay = np.array([0.0, 0.2, 2.0])
I = np.array([[10,20,30,40,50]])
I = np.concatenate((I,I,I,I,I), axis=0)
r_idx = np.arange(1, I.shape[0]+1)
c_idx = np.arange(1, I.shape[1]+1)
I_row = np.transpose(np.array([np.interp(ax, r_idx, I[:,x]) for x in range(0,I.shape[0])]))
I_col = np.array([np.interp(ay, c_idx, I_row[y,:]) for y in range(0, I_row.shape[0])])
SI = I_col
但是,生成的SI 是
SI =
10 10 20
10 10 20
10 10 20
为什么我使用 Python 的结果与使用 MATLAB 的结果不同?
【问题讨论】:
标签: python matlab numpy interpolation