I am using numpy to perform matrix multiplication, and I cannot figure out how to leverage numpy for 3d matrix multiplication.
Say I have a 3x3 matrix, a, and I multiply it by a 3x1 vector, b. This will give a 3x1 vector, c.
This is done in numpy with:
# (3, 3) * (3, 1) -> (3, 1)
c = np.matmul(a, b)
Ok, so now I want to perform a similar operation on a 3d matrix that is essentially 2500 3x3 matrices. Right now I am doing something to the effect of:
# (2500, 3, 3) * (2500, 3, 1) -> list of (3, 1) vectors with length 2500
C = [np.matmul(a, b) for a, b in zip(A, B)]
which returns a list of (3, 1) vectors.
I would rather NOT loop and instead fully leverage numpy's vectorization and matrix/tensor products. Is there some operation so I can do...
# (2500, 3, 3) * (2500, 3, 1) -> (2500, 3, 1)
np.<function>(A, B, <args>)
I've seen stuff about using np.tensordot, but I don't know how to set axes.
np.tensordot(A, B, axes=???)