0
1つの異なるディメンションで2つのテンソルを追加したいと思います。例えばTorch7:numpyのような不均一なサイズのテンソルを持つ加算層
:numpyので
x = torch.ones(4,5)
y = torch.ones(4,3,5)
私はこれを行うのcappableだ:
import numpy as np
x = np.ones((4,5))
y = np.ones((4,3,5))
y + x[:,None,:]
#Prints out
array([[[ 2., 2., 2., 2., 2.],
[ 2., 2., 2., 2., 2.],
[ 2., 2., 2., 2., 2.]],
[[ 2., 2., 2., 2., 2.],
[ 2., 2., 2., 2., 2.],
[ 2., 2., 2., 2., 2.]],
[[ 2., 2., 2., 2., 2.],
[ 2., 2., 2., 2., 2.],
[ 2., 2., 2., 2., 2.]],
[[ 2., 2., 2., 2., 2.],
[ 2., 2., 2., 2., 2.],
[ 2., 2., 2., 2., 2.]]])
It has a shape of (4,3,5)
がnn.CMulTable()
上でこれを再現する方法はありますか?私がこのようなx
テンソルを見るとx:view(4,1,5)
それは私にエラーinconsistent tensor size
を与える。
m = nn.CAddTable()
m:forward({y, x:view(4,1,5)})
4x3x5テンソル取得する
はどうもありがとうございました! – billiout