![](https://secure.gravatar.com/avatar/83e2e81183334c30c4089728bc9745d3.jpg?s=120&d=mm&r=g)
Is there any way to multiple a whole bunch of matrices together easily? Ideally, the * operator would be for matrix multiplication as opposed to element-by-element multiplication. I've been doing this: listofmatricies = [blah, blah, blah, ....] return reduce(matrixmultiply,listofmatricies) Seems to work, but it would nice to be able to do it in one line as in matlab. -- David J. Grant <http://www.davidgrant.ca:81> Get Firefox! <http://spreadfirefox.com/community/?q=affiliates&id=1621&t=70>
![](https://secure.gravatar.com/avatar/39916bae984cb93b797efd2b175f59c0.jpg?s=120&d=mm&r=g)
On Wed, 22 Sep 2004, David Grant apparently wrote:
Is there any way to multiple a whole bunch of matrices together easily? Ideally, the * operator would be for matrix multiplication as opposed to element-by-element multiplication. I've been doing this: listofmatricies = [blah, blah, blah, ....] return reduce(matrixmultiply,listofmatricies) Seems to work, but it would nice to be able to do it in one line as in matlab.
I didn't see a reply to this? Answer 1: reduce(matrixmultiply,[blah1, blah2, blah3,...]) Well, it's one line. ;-) Answer 2: if * didn't work for you, it is because you are working with arrays, not matrices. import Matrix x=Matrix.Matrix(blah1) y=Matrix.Matrix(blah2) print x*y You'll see matrix multiplication. fwiw, Alan Isaac
![](https://secure.gravatar.com/avatar/4d021a1d1319f36ad861ebef0eb5ba44.jpg?s=120&d=mm&r=g)
Alan G Isaac wrote:
On Wed, 22 Sep 2004, David Grant apparently wrote:
Is there any way to multiple a whole bunch of matrices together easily? Ideally, the * operator would be for matrix multiplication as opposed to element-by-element multiplication. I've been doing this: listofmatricies = [blah, blah, blah, ....] return reduce(matrixmultiply,listofmatricies) Seems to work, but it would nice to be able to do it in one line as in matlab.
Note that scipy has the easy-to-type commands mat and bmat mat will take a string like '1,2;3,4' to build a matrix and bmat takes 2-d matrices and builds other 2-d matrices with them. Once you get matrices you can use * for matrix multiplication and use the special methods .H Hermitian transpose .T transpose .I inverse .A (return the equivalent 2-d array) (i.e. for element-by-element multiplying) -Travis .
participants (3)
-
Alan G Isaac
-
David Grant
-
Travis Oliphant