【发布时间】:2018-11-20 09:13:39
【问题描述】:
正如问题所说,-1 在 pytorch view 中做了什么?
>>> a = torch.arange(1, 17)
>>> a
tensor([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.,
11., 12., 13., 14., 15., 16.])
>>> a.view(1,-1)
tensor([[ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.,
11., 12., 13., 14., 15., 16.]])
>>> a.view(-1,1)
tensor([[ 1.],
[ 2.],
[ 3.],
[ 4.],
[ 5.],
[ 6.],
[ 7.],
[ 8.],
[ 9.],
[ 10.],
[ 11.],
[ 12.],
[ 13.],
[ 14.],
[ 15.],
[ 16.]])
它 (-1) 会生成额外的维度吗?
它的行为是否与 numpy reshape -1 相同?
【问题讨论】:
-
据我所知(我不是专业人士..),给定的维度 -1 将适应其他维度。所以
a.view(-1,1)将产生一个维度为17x1的向量,因为有17 个值 - 所以v.view(1,-1)将产生一个1x17向量......
标签: pytorch reshape dimensions