📜  pytorch 张量加一维 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:45.478000             🧑  作者: Mango

代码示例1
# ADD ONE DIMENSION: .unsqueeze(dim)

my_tensor = torch.tensor([1,3,4])
# tensor([1,3,4])

my_tensor.unsqueeze(0)
# tensor([[1,3,4]])

my_tensor.unsqueeze(1)
# tensor([[1],
#         [3],
#         [4]])