In numpy, when i have a 3D tensor X with shape [A, B, C] and a 2D tensor Y with shape [C, D], then np.dot(X, Y) gives a 3D tensor with shape [A, B, D].
In PyTorch, i can do this as below.
result = torch.mm(X.view(-1, C), Y)
result = result.view(-1, B, D)
@chenyuntc, what you suggest would work but it’s an elementwise multiplication. @yunjey for the dot product, in pytorch it seems to only support 2D tensors. So yes, for the moment you have to vectorize (A and B) into one vector (for instance using view, or you can also use resize for almost simpler code:
result = torch.mm(X.resize_(A*B,C), Y).resize_(A,B,D)