评价此页

torch.swapdims#

torch.swapdims(input, dim0, dim1) Tensor#

torch.transpose() 的别名。

此函数等效于 NumPy 的 swapaxes 函数。

示例

>>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x
tensor([[[0, 1],
        [2, 3]],

        [[4, 5],
        [6, 7]]])
>>> torch.swapdims(x, 0, 1)
tensor([[[0, 1],
        [4, 5]],

        [[2, 3],
        [6, 7]]])
>>> torch.swapdims(x, 0, 2)
tensor([[[0, 4],
        [2, 6]],

        [[1, 5],
        [3, 7]]])