[SciPy-user] multiplying matrices

Alan G Isaac aisaac at american.edu
Wed Oct 13 23:43:17 CDT 2004


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





More information about the SciPy-user mailing list