• 文档 >
  • torch >
  • torch.movedim
快捷键

torch.movedim

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

input 的维度移动到 source 的位置上。

其他未显式移动的维度 input 将保持其原始顺序,并出现在 destination 中未指定的位置。

参数:
  • input (Tensor) – 输入张量。

  • 源(整数或整数元组)- 要移动的维度原始位置。这些必须唯一。

  • 目标(整数或整数元组)- 每个原始维度的目标位置。这些也必须唯一。

示例:

>>> 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]]])

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源