快捷方式

torch.movedim

torch.movedim(input, source, destination) Tensor

input 的維度,從 source 中指定的位置移動到 destination 中指定的位置。

沒有被明確移動的 input 的其他維度,會保持它們原來的順序,並出現在 destination 中沒有指定的位置。

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

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

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

範例

>>> 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 的完整開發者文件

檢視文件

教學

取得適用於初學者和進階開發人員的深入教學課程

檢視教學課程

資源

尋找開發資源並獲得問題解答

檢視資源