I have an array of matrices A
of shape A.shape = (N, 3, 3)
and an array of vectors V
of shape V.shape = (N, 3)
. I want to get an (N, 3) array, where each vector is the result of multiplying the n-th matrix with the n-th vector. Such as:
result = [A[i] @ V[i] for i in range(N)]
Is there a way of doing this without looping using NumPy? Ideally, I would also like this to work with arrays of higher dimensions, such as A.shape = (N, M, 3, 3)
and V.shape = (N, M, 3, 3)