oneflow.movedim

oneflow.movedim()

Moves the dimension(s) of input at the position(s) in source to the position(s) in destination. Other dimensions of input that are not explicitly moved remain in their original order and appear at the positions not specified in destination. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.movedim.html.

Parameters
  • input (Tensor) – the input tensor.

  • source (int or a list) – Original positions of the dims to move. These must be unique.

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

Returns

the output Tensor.

Return type

oneflow.Tensor

For example:

>>> import oneflow as flow
>>> import numpy as np

>>> input = flow.tensor(np.random.randn(2, 3, 4, 5), dtype=flow.float32)
>>> output = flow.movedim(input, 1, 0)
>>> output.shape
oneflow.Size([3, 2, 4, 5])
>>> output = flow.movedim(input, (1, 2), (0, 1))
>>> output.shape
oneflow.Size([3, 4, 2, 5])