1

I am rewriting a program from Matlab to Python. I realised a difference in a multiplication between arrays. Here is an example:

 A   = [-1822.87977846-4375.93518777j 
        3675.88618351+3824.34290883j
        971.68964707-2393.36758923j]

In Matlab:

A*A'= 5.7282e+07

In Python:

np.dot(A,A) = -21723405.178+39418085.0343j

How to obtain the same result of A'*A in Numpy?

Thank you.

1
  • 2
    You see the ` in the Matlab-code? Yeah, it's important and not reflected within your python-code :-). Hint: complex conjugate transpose operator. Commented Feb 18, 2017 at 21:22

3 Answers 3

4

First of all remember, in MATLAB, ' is different than .'.

' does complex conjugate transpose

.' does non-conjugate transpose

On a real value vector or matrix both operators obtain similar result. However, on complex vectors or matrices they obtain different results. Check the links to find matlab examples for both.

In MATLAB, you can do the following:

A.'*A

ans =

     -2.172340517799748e+07 + 3.941808503424492e+07i
Sign up to request clarification or add additional context in comments.

3 Comments

Few people know the difference between .' and ' in Matlab. Most would just use '. Well done +1
Thank you, very useful reply. Do you know how to obtain the A'*A operation in Numpy?
check the answer by @hpaulj
2

On the Python side

In [488]: A=np.array( [-1822.87977846-4375.93518777j ,
     ...:         3675.88618351+3824.34290883j,
     ...:         971.68964707-2393.36758923j])
In [489]: A
Out[489]: 
array([-1822.87977846-4375.93518777j,  3675.88618351+3824.34290883j,
         971.68964707-2393.36758923j])
In [490]: A.conj()
Out[490]: 
array([-1822.87977846+4375.93518777j,  3675.88618351-3824.34290883j,
         971.68964707+2393.36758923j])
In [491]: A.dot(A.conj())
Out[491]: (57281826.560119703+0j)
In [492]: A.dot(A)
Out[492]: (-21723405.177997477+39418085.034244925j)
In [497]: np.vdot(A,A)
Out[497]: (57281826.560119703+0j)

In Octave, as pointed out in the other answer

>> A'*A
ans =    5.7282e+07
>> A.'*A
ans = -2.1723e+07 + 3.9418e+07i
>>

3 Comments

Thank you, indeed I would like to obtain the A'*A operation in Numpy!
Add a .real to my answers to remove the 0j part.
plus-one For the Python side answer! :) +1
1

To obtain the A*A' Matlab operation in Numpy, you can do:

np.dot(A,np.conj(A))

Thank you!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.