matrix multiplication (newbie question)

Sven Schreiber svetosch at gmx.net
Wed Nov 8 09:51:09 EST 2006


izak marais schrieb:
> Hi
> 
> Sorry if this is an obvious question, but what is the easiest way to
> multiply matrices in numpy? Suppose I want to do A=B*C*D. The ' * '
> operator apparently does element wise multiplication, as does the
> 'multiply' ufunc. All I could find was the numeric function
> 'matrix_multiply, but this only takes two arguments.
> 
> Thanks in advance!
> Izak

There are (at least) two ways:

You can use 'dot', possibly nested.

or you can convert your arrays into the matrix subclass, for which '*'
is matrix multiplication. I.e. mat(B)*mat(C)*mat(D) does what you want.

If you "only" deal with algebra-style matrices (2d-arrays), consider
using the matrix subclass as much as you can. E.g. use the functions in
numpy.matlib to build your inputs.
-sven

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list