小编qim*_*ang的帖子

pytorch 变量索引丢失了一维

我将获得一个变量中的每个水平张量,但我丢失了一个维度。

这是我的代码:

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)

python neural-network reshape deep-learning pytorch

6
推荐指数
1
解决办法
2277
查看次数

标签 统计

deep-learning ×1

neural-network ×1

python ×1

pytorch ×1

reshape ×1