From: Sven S. <sve...@gm...> - 2006-11-08 14:52:25
|
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 |