torch.movedim¶
- torch.movedim(input, source, destination) Tensor ¶
將
input
的維度,從source
中指定的位置移動到destination
中指定的位置。沒有被明確移動的
input
的其他維度,會保持它們原來的順序,並出現在destination
中沒有指定的位置。- 參數
範例
>>> 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]]])