I have a list of 3D points p stored in an ndarray with shape (N, 3). For each point, I have a rotation matrix R with shape (3,3), so the ndarray of matrices M has shape (N, 3, 3). I'd like to compute the dot product of R.x for each point x in p and each rotation R in M. Naively I can do this:
N = int(1e4)
p = np.random.random((N, 3))
M = np.random.random((N, 3, 3))
result = np.zeros_like(p)
for i in range(N):
result[i, :] = np.dot(M[i, :, :], p[i, :])
Is there a way to do this without the python-layer for loop?
Note that this question generalizes the closely related question Efficiently rotate a set of points with a rotation matrix in numpy