它在MATLAB/OCTAVE中工作-如何在Python中正确地修复它:
octave:40> whos YDFA_ale_ase
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
YDFA_ale_ase 51x1 408 double
Total is 51 elements using 408 bytes
octave:41> whos N1
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
N1 1x1200 9600 double
Total is 1200 elements using 9600 bytes
octave:45> YDFA_ale_ase * N1
ans =
Columns 1 through 20:
46.8270 46.8270 46.8270
..........................
但在Python中,我得到以下错误:
np.dot(YDFA_ale_ase, 1.-N1)-np.dot(YDFA_ala_ase, N1)
ValueError: matrices are not aligned
其他尝试:
YDFA_ale_ase* 1.-N1-YDFA_ala_ase* N1
ValueError: operands could not be broadcast together with shapes (51) (1,1200)
但是:
print YDFA_ale_ase.shape, N1.shape
给了我
(51,) (1, 1200)
打印阵列的形状。请记住,Matlab矩阵至少有2个dim,而NUMPY可以是1甚至0。很可能您正试图用
dot
和(1,m)
来(n,)
。在( n,)
数组的右侧添加维度Y[:, None]
是最简单的方法http://wiki.scipy.org/NumPy_for_Matlab_Users
相关问题 更多 >
编程相关推荐