Alex Rivera | Logout

Efficiently rotate a set of points with a rotation matrix in numpy

Asked 2012-08-27T19:30:57.667
25

I have a list of 3D points stored in numpy array A with shape (N,3) and a rotation matrix R with shape (3,3). I'd like to compute the dot product of R.x for each point x in A in-place. Naively I can do this:

for n in xrange(N):
    A[n,:] = dot(R, A[n,:]) 

Is there a way to vectorize this with a native numpy call? If it matters, N is on order of a couple thousand.

Edit
Report

1 Answer

38

You can multiply A with the transpose of the rotation matrix:

A = dot(A, R.T)
answered 2012-08-27T19:41:25.070

Your Answer