Dot product and matmul

I have tensor x shape = torch.Size([32, 69, 64]) and y = torch.Size([32, 69, 68, 64]). I want output to be torch.Size([32, 69, 68, 1]). matrix multiplication of [1,64] and [68,64] to [68,1].

Hi Rohit!

Try:

torch.einsum ('ijl, ijkl -> ijk', x, y).unsqueeze (-1)

The einsum() “contracts” over the “64” dimension, while the
.unsqueeze (-1) adds the trailing singleton dimension.

Best.

K. Frank