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