PyTorch中的view函數(shù)可以改變tensor的形狀
eg1
import torch
test = torch.zeros(2,3)
print(test)
print(test.view(3,-1)) #-1表示程序會(huì)根據(jù)上一個(gè)維度自動(dòng)計(jì)算-1所在位置的維度
#tensor([[0., 0., 0.],
# [0., 0., 0.]])
#tensor([[0., 0.],
# [0., 0.],
# [0., 0.]])
eg2
test = torch.Tensor([1,2,3,4,5,6,7,8])
print(test)
print(test.view(4,2))
# tensor([1., 2., 3., 4., 5., 6., 7., 8.])
#tensor([[1., 2.],
# [3., 4.],
# [5., 6.],
# [7., 8.]])