pytorch中和unsqueeze一样的维度扩充方法

torch.arange((10))[None, :],torch.arange((10))[:,None] #在外面增加了一个维度
output:
(tensor([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]),
 tensor([[0],
         [1],
         [2],
         [3],
         [4],
         [5],
         [6],
         [7],
         [8],
         [9]]))
torch.arange((10))[None, :].shape,torch.arange((10))[:,None].shape
output:
(torch.Size([1, 10]), torch.Size([10, 1]))
posted @ 2021-11-16 11:40  zae  阅读(80)  评论(0编辑  收藏  举报