maxframe.tensor.moveaxis#

maxframe.tensor.moveaxis(a, source, destination)[源代码]#

将张量的轴移动到新位置。

其他轴保持原始顺序不变。

参数:
  • a (Tensor) -- 需要重新排列轴的张量。

  • source (int or sequence of int) -- 要移动的轴的原始位置。这些位置必须唯一。

  • destination (int or sequence of int) -- 每个原始轴的目标位置。这些位置也必须唯一。

返回:

result -- 轴已移动的数组。此张量是输入张量的视图。

返回类型:

Tensor

参见

transpose

重新排列数组的维度。

swapaxes

交换数组的两个轴。

示例

>>> import maxframe.tensor as mt
>>> x = mt.zeros((3, 4, 5))
>>> mt.moveaxis(x, 0, -1).shape
(4, 5, 3)
>>> mt.moveaxis(x, -1, 0).shape
(5, 3, 4),

这些操作都实现相同的结果:

>>> mt.transpose(x).shape
(5, 4, 3)
>>> mt.swapaxes(x, 0, -1).shape
(5, 4, 3)
>>> mt.moveaxis(x, [0, 1], [-1, -2]).shape
(5, 4, 3)
>>> mt.moveaxis(x, [0, 1, 2], [-1, -2, -3]).shape
(5, 4, 3)