[Numpy-discussion] Apply transform to many small matrices

Jorge Scandaliaris jorgesmbox-ml@yahoo...
Wed Feb 27 06:57:02 CST 2013

First of all excuse me if this is a trivial question. I have the feeling it is,
but searching and looking through the docs has proven unsuccesful so far.

I have an ndarray A of shape (M,2,2) representing M 2 x 2 matrices. Now I want
to apply a transform T of shape (2,2) to each of matrix. The way I do this now
is by iterating over all rows of A multiplying the matrices using numpy.dot():

for row in np.arange(A.shape[0]):
    A[row] = np.dot(A[row],T)

but this seems to be slow when M is large and I have the feeling there must be a
way of doing it better.



More information about the NumPy-Discussion mailing list