PHP前端开发

挤入 PyTorch

百变鹏仔 5天前 #Python
文章标签 PyTorch

请我喝杯咖啡☕

*我的帖子解释了 unsqueeze()。

squeeze() 可以从零个或多个元素的 0d 或多个 d 张量中获取删除零个或多个维度的零个或多个元素的 0d 或多个 d 张量,如果大小为 1,如下所示:

*备忘录:

import torchmy_tensor = torch.tensor([[[[0], [1]],                           [[2], [3]],                           [[4], [5]]]])torch.squeeze(input=my_tensor)my_tensor.squeeze()torch.squeeze(input=my_tensor, dim=(0, 3))my_tensor.squeeze(dim=(0, 3))my_tensor.squeeze(0, 3)torch.squeeze(input=my_tensor, dim=(0, 1, 3))my_tensor.squeeze(dim=(0, 1, 3))my_tensor.squeeze(0, 1, 3)etc.torch.squeeze(input=my_tensor, dim=(0, 1, 2, 3))my_tensor.squeeze(dim=(0, 1, 2, 3))my_tensor.squeeze(0, 1, 2, 3)etc.# tensor([[0, 1],#         [2, 3],#         [4, 5]])torch.squeeze(input=my_tensor, dim=0)torch.squeeze(input=my_tensor, dim=-4)torch.squeeze(input=my_tensor, dim=(0,))torch.squeeze(input=my_tensor, dim=(-4,))torch.squeeze(input=my_tensor, dim=(0, 1))torch.squeeze(input=my_tensor, dim=(0, 2))torch.squeeze(input=my_tensor, dim=(0, -2))torch.squeeze(input=my_tensor, dim=(0, -3))torch.squeeze(input=my_tensor, dim=(1, 0))etc.torch.squeeze(input=my_tensor, dim=(0, 1, 2))etc.# tensor([[[0], [1]],#         [[2], [3]],#         [[4], [5]]])torch.squeeze(input=my_tensor, dim=1)torch.squeeze(input=my_tensor, dim=2)torch.squeeze(input=my_tensor, dim=-2)torch.squeeze(input=my_tensor, dim=-3)torch.squeeze(input=my_tensor, dim=())torch.squeeze(input=my_tensor, dim=(1,))torch.squeeze(input=my_tensor, dim=(2,))torch.squeeze(input=my_tensor, dim=(-2,))torch.squeeze(input=my_tensor, dim=(-3,))torch.squeeze(input=my_tensor, dim=(1, 2))etc.# tensor([[[[0], [1]],#          [[2], [3]],#          [[4], [5]]]])torch.squeeze(input=my_tensor, dim=3)torch.squeeze(input=my_tensor, dim=-1)torch.squeeze(input=my_tensor, dim=(3,))torch.squeeze(input=my_tensor, dim=(-1,))torch.squeeze(input=my_tensor, dim=(1, 3))torch.squeeze(input=my_tensor, dim=(1, -1))torch.squeeze(input=my_tensor, dim=(2, 3))torch.squeeze(input=my_tensor, dim=(2, -1))torch.squeeze(input=my_tensor, dim=(3, 1))etc.torch.squeeze(input=my_tensor, dim=(1, 2, 3))etc.# tensor([[[0, 1],#          [2, 3],#          [4, 5]]])my_tensor = torch.tensor([[[[0.], [1.]],                           [[2.], [3.]],                           [[4.], [5.]]]])torch.squeeze(input=my_tensor)# tensor([[0., 1.],#         [2., 3.],#         [4., 5.]])my_tensor = torch.tensor([[[[0.+0.j], [1.+0.j]],                           [[2.+0.j], [3.+0.j]],                           [[4.+0.j], [5.+0.j]]]])torch.squeeze(input=my_tensor)# tensor([[0.+0.j, 1.+0.j],#         [2.+0.j, 3.+0.j],#         [4.+0.j, 5.+0.j]])my_tensor = torch.tensor([[[[True], [False]],                           [[False], [True]],                           [[True], [False]]]])torch.squeeze(input=my_tensor)# tensor([[True, False],#         [False, True],#         [True, False]])