zhydong
(Zhang Yidong)
January 26, 2019, 1:35pm
1
I have a vector atten
and a tensor feat
. The shapes are:
>>> atten.shape
torch.Size([1, 13])
>>> feat.shape
torch.Size([13, 1024, 7, 7])
I want to do below calculation:
sum_i(atten[0][i] * feat[i])
I tried torch.matmul
or *
directly, but it didn’t work. Does anybody know how to make it right?
tom
(Thomas V)
January 26, 2019, 4:45pm
3
torch.einsum('i,ijkl', atten[0], feat)
Best regards
Thomas
zhydong
(Zhang Yidong)
January 27, 2019, 1:42am
4
thanks! but I’m using pytorch 0.3 which seems not having torch.einsum
method
tom
(Thomas V)
January 27, 2019, 6:11am
6
That’s a great occasion to upgrade! I don’t think its a reason in itself, but you’ll likely soon find yourself in a similar situation with something else. Just not having to fiddle with variables would be a good reason for me to upgrade.
Best regards
Thomas
zhydong
(Zhang Yidong)
January 28, 2019, 1:58am
7
yes, your solution works~谢了兄弟!