PyTorch基础——torch.Tensor.permute(...)和torch.transpose(...)

torch.permute可以进行多个维度的交换,而torch.transpose只能进行两个维度的交换

In [1]: dat = torch.tensor(
                [[[ 1,  2,  3,  4],
                  [ 5,  6,  7,  8],
                  [ 9, 10, 11, 12]],

                [[13, 14, 15, 16],
                 [17, 18, 19, 20],
                 [21, 22, 23, 24]]])
In [2]: dat.shape
Out[2]: torch.Size([2, 3, 4])

In [3]: dat_transpose = torch.transpose(dat, 1,2)
In [4]: dat_transpose.shape
Out[4]: torch.Size([2, 4, 3])

In [5]: dat_permute = dat.permute((1,2,0))
In [6]: dat_permute.shape
Out[6]: torch.Size([3,4,2])

你可能感兴趣的:(PyTorch,permute,transpose)