Reputation: 125
I have a 500x2 numpy array and a 2x2 rotation array. I would like to rotate each row of the array using the rotation array.
I have tried
R.dot(A)
where R is the rotation array and A is the 500x2 array. But get the following error:
shapes (2,2) and (500,2) not aligned: 2 (dim 1) != 500 (dim 0)
Is there a way to do this row by row?
Thanks
Upvotes: 0
Views: 214
Reputation: 46
For matrix multiplication, you need the inner dimensions to match (m
by n
and n
by k
). You're trying to multiply a 2 by 2 matrix with a 500 by 2 matrix - you need to take the transpose of the second matrix. Try
R.dot(A.transpose())
The columns of the result should be your rotated vectors. If you need it to be in row form, you can take the transpose again:
R.dot(A.transpose()).transpose()
Upvotes: 2