简体   繁体   English

从MATLAB转换为python时,矩阵乘法会呈现不同的结果

[英]Matrix multiplication renders different results when converting from MATLAB to python

I have an MxN matrix A where A is complex and apparently has some properties which renders a diagonal matrix for A'*A . 我有一个MxN矩阵A ,其中A是复数,并且显然具有一些属性,从而为A'*A呈现对角矩阵。 A is also very large (256x16384) so I cannot think of a way to upload it here for reproducing. A也非常大(256x16384),所以我想不出一种将其上传到此处进行复制的方法。

In the MATLAB code, I have: 在MATLAB代码中,我有:

imshow(abs(A'*A),[]);

this produces the following image: 这将产生以下图像: 在此处输入图片说明

The converted code in python: 在python中转换的代码:

tmp=np.dot(A.T,A)
plt.imshow(np.absolute(tmp))
plt.show()

produces: 产生:

在此处输入图片说明

The diagonal seemed to rotate. 对角线似乎在旋转。 Is there any reason for this rotation? 轮换有什么原因吗? Am I doing the conversion correctly? 我转换正确吗?

I guess that you're confusing between the transpose and the conjugate transpose operator. 我猜您在转置和共轭转置运算符之间感到困惑。

Matlab to Python: Matlab到Python:

transpose : 转置

  • Matlab: A.' Matlab: A.'
  • Python: AT Python: AT

conjugate tranpose : 共轭转置

  • Matlab: A' Matlab: A'
  • Python: A.conj().T Python: A.conj().T

So change your matlab code or your python code according to your need. 因此,根据需要更改您的matlab代码或python代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Matlab和Python中矩阵乘法和求幂的结果不同 - Different results in Matlab and Python for matrix multiplication and exponentiation 与Matlab进行比较时,python中Matrix与向量的乘法是不同的 - Multiplication of Matrix by vector in python is different when comparing with Matlab MATLAB 和 Python 中的逆矩阵结果不同 - Inverse matrix results different in MATLAB and Python 使用Python和R语言进行矩阵乘法的结果不同 - Different results in matrix multiplication using Python and R language 已知结果稀疏度时的稀疏矩阵乘法(在python | scipy | cython中) - Sparse matrix multiplication when results' sparsity is known (in python|scipy|cython) matlab 和 python 中复数矩阵乘法的区别 - Difference between complex matrix multiplication in matlab and python 为什么在 Matlab 和 Python 中欧拉到旋转矩阵的结果不同 - Why different results for Euler to Rotation Matrix in Matlab and Python 将 matlab 代码转换为 python 后,我得到了不同的结果 - After converting matlab code to python, I'm getting different results 将matlab中的矩阵转换为python中的numpy assray时面临的问题 - Facing issues when converting a matrix in matlab into numpy assray in python 矩阵乘法Python与Swift的不同输出 - Different Output in matrix Multiplication Python vs Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM