當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python PyTorch moveaxis用法及代碼示例

本文簡要介紹python語言中 torch.moveaxis 的用法。

用法:

torch.moveaxis(input, source, destination) → Tensor

torch.movedim() 的別名。

這個函數相當於 NumPy 的 moveaxis 函數。

例子:

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

        [[-0.9627],
        [ 0.1727]],

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

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

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

相關用法


注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.moveaxis。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。