我将获得一个变量中的每个水平张量,但我丢失了一个维度。
这是我的代码:
import torch
from torch.autograd import Variable
t = torch.rand((2,2,4))
x = Variable(t)
print(x)
shape = x.size()
for i in range(shape[0]):
for j in range(shape[1]):
print(x[i,j])
Run Code Online (Sandbox Code Playgroud)
输出是:
Variable containing:
(0 ,.,.) =
0.6717 0.8216 0.5100 0.9106
0.3280 0.8182 0.5781 0.3919
(1 ,.,.) =
0.8823 0.4237 0.6620 0.0817
0.5781 0.4187 0.3769 0.0498
[torch.FloatTensor of size 2x2x4]
Variable containing:
0.6717
0.8216
0.5100
0.9106
[torch.FloatTensor of size 4]
Variable containing:
0.3280
0.8182
0.5781
0.3919
[torch.FloatTensor of size 4]
Variable containing:
0.8823
0.4237 …Run Code Online (Sandbox Code Playgroud)