I suppose that you want to multiply mat1 with each 25*36 matrix in mat2 (36 matrices in total, i.e. mat2.shape[-1]), and finally get 36 results.
The following code may work :
import torch
b = 256
mat1 = torch.randn(b, 25)
mat2 = torch.randn(25, 36, 36)
mat2_p = mat2.permute(2, 0, 1) # move the last dimension (matrix number) to the first
res = torch.matmul(mat1, mat2_p)
res = res.permute(1, 2, 0) # restore
print(res.shape)
Thank you so much for your quick response @111414 .
I am sorry I did not describe it clearly.
I actually want the dim1 of mat1 as weights to integrate mat2 along dim0 of mat2, then I will get a matrix (batch, 36,36).
Like
mat1: batchxn1,
mat2: n1xn2xn3,
then mat1*mat2 → batchxn2xn3.