Rate this Page

torch.movedim#

torch.movedim(input,source,destination)Tensor#

Moves the dimension(s) ofinput at the position(s) insourceto the position(s) indestination.

Other dimensions ofinput that are not explicitly moved remain intheir original order and appear at the positions not specified indestination.

Parameters
  • input (Tensor) – the input tensor.

  • source (int ortuple ofints) – Original positions of the dims to move. These must be unique.

  • destination (int ortuple ofints) – Destination positions for each of the original dims. These must also be unique.

Examples:

>>>t=torch.randn(3,2,1)>>>ttensor([[[-0.3362],        [-0.8437]],        [[-0.9627],        [ 0.1727]],        [[ 0.5173],        [-0.1398]]])>>>torch.movedim(t,1,0).shapetorch.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)).shapetorch.Size([2, 1, 3])>>>torch.movedim(t,(1,2),(0,1))tensor([[[-0.3362, -0.9627,  0.5173]],        [[-0.8437,  0.1727, -0.1398]]])