Search code examples
pythonmatlabmatrix-multiplicationtranslatecomplex-numbers

Difference between complex matrix multiplication in matlab and python


I'm trying to translate a program from matlab to python and I don't get one piece to work. In this line of the code I'm trying to multiply 2 complex arrays:

Matlab: Croco2=refAntDiag_norm'*testAntDiag_norm;

Python: Croco2 = np.matmul(refAntDiag_norm.transpose(), testAntDiag_norm))

But the Outputs are different.

Does anybody have an idea on how to fix this?


Solution

  • In MATLAB, this operator: ' is the complex conjugate transpose, not just a normal transpose which numpy's .transpose() is doing.

    MATLAB's transpose operator is .'.

    So the MATLAB code equivalent to what you have in Python would be

    Croco2=refAntDiag_norm.'*testAntDiag_norm;
    

    From the docs, it looks like the numpy equivalent for the complex conjugate transpose is .H.