TensorDictBase.movedim#
- TensorDictBase.movedim(source: int | tuple[int, ...], destination: int | tuple[int, ...])#
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.
- Parameters:
- Returns:
a new tensordict with the batch dimensions moved to the desired positions.
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict({"a": torch.randn(3, 4, 5)}, batch_size=[3, 4]) >>> print(td.movedim(0, 1).shape) torch.Size([4, 3]) >>> print(td.movedim((0, 1), (1, 0)).shape) torch.Size([4, 3])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.