关于.squeeze()方法
输入:
a = torch.rand([4,1,3,2,1,5]) print(a.shape) b = a.squeeze() print(b.shape) a1 = torch.rand([4,1,3,2,1,5]) print(a1.shape) c = a1[0].squeeze() print(c.shape) d = a1[1].squeeze() print(d.shape) e = a1[2].squeeze() print(e.shape)
输出:
torch.Size([4, 1, 3, 2, 1, 5]) torch.Size([4, 3, 2, 5]) torch.Size([4, 1, 3, 2, 1, 5]) torch.Size([3, 2, 5]) torch.Size([3, 2, 5]) torch.Size([3, 2, 5]) Process finished with exit code 0
.squeeze(a,axis = None)
axis的取值可为None 或 int 或 tuple of ints, 可选。若axis为空,则删除所有单维度的条目;



