Efficient way to multiply n matrices to another n matrices

I have two sets of matrices.
Set A includes 10 matrices with the same size of [11x3].
Set B includes 10 matrices with the same size of [3x100].
I want to multiply the i-th matrix in set A with the i-th matrix in set B. What is the most efficient way to do this?

Thanks a lot.

So, you have Tensor A of shape [10, 11, 3] and Tensor B of shape [10, 3, 100]? torch.matmul will do the trick.

A = torch.randn(10,11,3)
B = torch.randn(10,3,100)
C = torch.matmul(A,B) #returns Tensor of shape [10,11,100]
2 Likes