[Numpy-discussion] Apply transform to many small matrices
Wed Feb 27 17:44:26 CST 2013
On 27 Feb 2013 12:57, "Jorge Scandaliaris" <email@example.com> wrote:
> First of all excuse me if this is a trivial question. I have the feeling
> 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
> to apply a transform T of shape (2,2) to each of matrix. The way I do
> is by iterating over all rows of A multiplying the matrices using
> for row in np.arange(A.shape):
> 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.
Pretty sure the code you wrote above is equivalent to
np.dot(A, T, out=A)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion