Your most versatile function for matrix multiplication is torch.einsum
: it allows you specify the dimensions along which to multiply and the order of the dimensions of the output tensor.
In your case it would look like:
dot_product = torch.einsum('bij,bj->bi')
solved How to perform multiplication along axes in pytorch?