【发布时间】:2020-05-02 15:29:31
【问题描述】:
我正在尝试将我的 MATLAB 代码转换为 Python。
在 MATLAB 中,OP 是 300x300 double 数组,mask 是 300x300 logical 数组。
t1 = mask(:) 等于 90000x1 logical 数组。
t2 = OP(mask(:)) 的输出怎么可能等于57664x1 double 数组?
这是我的 MATLAB 代码:
OP=repmat(Ph,size(image,1),1).*repmat(Pv,1,size(image,2));
t1 = mask(:)
t2 = OP(mask(:))
data=sort(OP(mask(:)),'descend');
另外,在 Python 中,我使用 Numpy 来实现我的 MATLAB 代码,但 OP[mask] 是 MATLAB 转换的 OP(mask(:)) 是 90000x1x300 ndarray。我不知道如何解决它。
这是我的python代码:
OP = np.matlib.repmat(Ph, image.shape[0], 1) * np.matlib.repmat(Pv, 1, image.shape[1])
t2 = OP[mask]
data = -np.sort(-OP[mask], axis=0)
我知道t1、OP 和 mask 的大小与其在 MATLAB 中的类似变量的大小相同。
如果有人可以帮助我,我将不胜感激。
【问题讨论】:
-
你能把你的问题改写成MCVE吗?
标签: python arrays matlab numpy