[Numpy-discussion] vectorized multi-matrix multiplication

Alex Flint alex.flint at gmail.com
Sun Aug 26 11:04:51 EDT 2012

I have two lists of 3x3 arrays and I would like to compute the matrix
product of the i-th element in the first list with the i-th element in
the second list. Of course, I could just loop over the lists:

for i in range(n):
     out[i] = dot( matrices1[i], matrices2[i] )

However, the list is quite long, and each matrix is very small (3x3)
so this turns out to be quite slow. Is there a way to do this with a
single numpy call? I have looked at tensordot but it outputs an N x N
x 3 x 3 array, whereas I want an N x 3 x 3 output. I've also looked at
various broadcasting tricks but I haven't found anything that works


More information about the NumPy-Discussion mailing list