matrix multiplication (newbie question)

Sven Schreiber svetosch at
Wed Nov 8 08:51:09 CST 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.

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

More information about the Numpy-discussion mailing list