Matrice Multiplication Problem

M

mclaugb

I want to multiply two arrays: a matrice and the conjugate of its
transpose. Then i wish to invert the resulting matrix.

In Matlab, the statement is : Z= inv(M .' * M)

To implement in python, I simply cannot get this to work. Here is my code:

from numpy import *
import scipy as Sci
from scipy.linalg import lu
m=array([[4,6+7j],[3+3j,7],[2+2j,4-7j]])
z=m.conj().transpose()
q=z*m


Traceback (most recent call last):
File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 3241, in runcode
locals = self.frame.f_locals)
File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 1583, in runcode
h_exec(code, globals=globals, locals=locals, module=module)
File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 520, in __init__
exec code in globals, locals
File "<console>", line 0, in __main__
ValueError: index objects are not broadcastable to a single shape
 
R

Robert Kern

mclaugb said:
I want to multiply two arrays: a matrice and the conjugate of its
transpose. Then i wish to invert the resulting matrix.

You will want to ask numpy questions on the numpy mailing list.

http://www.scipy.org/Mailing_Lists
In Matlab, the statement is : Z= inv(M .' * M)

To implement in python, I simply cannot get this to work. Here is my code:

from numpy import *
import scipy as Sci
from scipy.linalg import lu
m=array([[4,6+7j],[3+3j,7],[2+2j,4-7j]])
z=m.conj().transpose()
q=z*m

numpy arrays are not matrices. * performs elementwise multiplication. Use
numpy.dot(z, m).

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top