Oh right! ‘squeeze’ and ‘unsqueeze’ are more suitable than ‘view’.
but there is still the problem that two tensor of different size cannot be multiplied element-wisely, not different rank.
(i.e. a (2x1x3 tensor) * b (2x2x3 tensor) , ‘*’ denotes element-wise multiplication)
it can be solved by using ‘expand’
so, I suggest the following for people watching this discussion,
a = torch.LongTensor([[1,2,3],[4,5,6]])
b = [torch.LongTensor([[1,1],[1,1]]),
torch.LongTensor([[2,2],[4,4]]),
torch.LongTensor([[3,3],[9,9]])]
b = torch.stack(b, dim=2)
c = b.mul(a.unsqueeze(1).expand_as(b)).sum(dim=2).squeeze()
I really appreciate for your helpful comments.
@lantiga