# [Numpy-discussion] Iterative Matrix Multiplication

Friedrich Romstedt friedrichromstedt at gmail.com
Mon Mar 1 06:12:43 EST 2010

```2010/3/1 Charles R Harris <charlesr.harris at gmail.com>:
> On Sun, Feb 28, 2010 at 7:58 PM, Ian Mallett <geometrian at gmail.com> wrote:
>> Excellent--and a 3D rotation matrix is 3x3--so the list can remain n*3.
>> Now the question is how to apply a rotation matrix to the array of vec3?
>
> It looks like you want something like
>
> res = dot(vec, rot) + tran
>
> You can avoid an extra copy being made by separating the parts
>
> res = dot(vec, rot)
> res += tran
>
> where I've used arrays, not matrices. Note that the rotation matrix
> multiplies every vector in the array.

When you want to rotate a ndarray "list" of vectors:

>>> a.shape
(N, 3)

>>> a
[[1., 2., 3. ]
[4., 5., 6. ]]

by some rotation matrix:

>>> rotation_matrix.shape
(3, 3)

where each row of the rotation_matrix represents one vector of the
rotation target basis, expressed in the basis of the original system,

you can do this by writing:

>>> numpy.dot(a, rotations_matrix)  ,

as Chuck pointed out.

This gives you the rotated vectors in an ndarray "list" again:

>>> numpy.dot(a, rotation_matrix).shape
(N, 3)

This is just somewhat more in detail what Chuck already stated
> Note that the rotation matrix
> multiplies every vector in the array.

my 2 cents,
Friedrich

```