import torch as t
a=t.arange(1.0,10,1)
print(a)
print(a.shape,a.size())
a=a.view(1,1,9,1)
print(a)
print(a.shape,a.size())
a=a.view(9)
print(a)
a=a.unsqueeze(1)
print(a)
print(a.shape,a.size())
a=a.squeeze(1)
print(a)
print(a.shape,a.size())
/home/wangbin/anaconda3/envs/deep_learning/bin/python3.7 /home/wangbin/anaconda3/envs/deep_learning/project/main.py
tensor([1., 2., 3., 4., 5., 6., 7., 8., 9.])
torch.Size([9]) torch.Size([9])
tensor([[[[1.],
[2.],
[3.],
[4.],
[5.],
[6.],
[7.],
[8.],
[9.]]]])
torch.Size([1, 1, 9, 1]) torch.Size([1, 1, 9, 1])
tensor([1., 2., 3., 4., 5., 6., 7., 8., 9.])
tensor([[1.],
[2.],
[3.],
[4.],
[5.],
[6.],
[7.],
[8.],
[9.]])
torch.Size([9, 1]) torch.Size([9, 1])
tensor([1., 2., 3., 4., 5., 6., 7., 8., 9.])
torch.Size([9]) torch.Size([9])
Process finished with exit code 0