快捷方式

torch.movedim

torch.movedim(input, source, destination) Tensor

input 中位於 source 位置的維度移動到 destination 位置。

input 中未顯式移動的其他維度保留其原始順序,並出現在 destination 中未指定的位置。

引數
  • input (Tensor) – 輸入張量。

  • source (inttupleints) – 要移動的維度的原始位置。這些位置必須是唯一的。

  • destination (inttupleints) – 每個原始維度的目標位置。這些位置也必須是唯一的。

示例

>>> t = torch.randn(3,2,1)
>>> t
tensor([[[-0.3362],
        [-0.8437]],

        [[-0.9627],
        [ 0.1727]],

        [[ 0.5173],
        [-0.1398]]])
>>> torch.movedim(t, 1, 0).shape
torch.Size([2, 3, 1])
>>> torch.movedim(t, 1, 0)
tensor([[[-0.3362],
        [-0.9627],
        [ 0.5173]],

        [[-0.8437],
        [ 0.1727],
        [-0.1398]]])
>>> torch.movedim(t, (1, 2), (0, 1)).shape
torch.Size([2, 1, 3])
>>> torch.movedim(t, (1, 2), (0, 1))
tensor([[[-0.3362, -0.9627,  0.5173]],

        [[-0.8437,  0.1727, -0.1398]]])

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源