Pytorch Matrix element wise multiplication
Let's say I have two tensors A of shape : [32 , 512] and B of shape : [32 , 512], 
And I want to do element-wise multiplication between the vectors of the matrix to get a new matrix of shape : [32 , 1] (first row of A with first row of B, and second row of A with second row of B and so on.. ) , current methods I have tried simply mul the matrix values and not rows and gives a matrix of shape : [32 , 512].  
Thanks!

I guess this is equivalent of what you're looking for, first a matrix multiplication, then sum over each row. [associative law]

import torch

a = torch.zeros(31,512)
b = torch.zeros(31,512)

c = torch.sum(torch.mm(a,torch.t(b)), dim=1).unsqueeze(-1)
print(c.shape)


Out:

torch.Size([31, 1])

