Fork me on GitHub 0

reshape&view&transpose

x = torch.tensor([1, 2, 3])
tensor([[1, 1, 1],
        [2, 2, 2],
        [3, 3, 3]])
x.reshape(-1)
tensor([1, 1, 1, 2, 2, 2, 3, 3, 3])

 view

a = torch.arange(0,20)	
a.view(4,5).shape
a.view(-1,5).shape (4,5)
a.view(4,5).shape (4,5)
#-1表示该为不知道设置多少

 

?view(-1,1,4) view(1,-1,4)

 

transpose

b = a.transpose(1, 2)  # Swaps 2nd and 3rd dimension

  

  

posted @ 2020-09-23 22:36  amazingcode  阅读(185)  评论(0编辑  收藏  举报