Skip to content

pymath.transpose

Daniel Flassig edited this page Jun 24, 2026 · 1 revision

Returns a new tensor (rank ≥ 2) with two axes exchanged. With the default axes this is the ordinary matrix transpose.

This function is located in the pymath module. See pymath for the tensor representation.

result = pymath.transpose(m [, axis1 [, axis2]])
Parameter Type Description
m tensor Input tensor of rank ≥ 2.
axis1 integer 1-based first axis to exchange. Defaults to 1. 0 selects the default.
axis2 integer 1-based second axis to exchange. Defaults to 2. 0 selects the default.

Return value

Type Description
result A new tensor with the sizes of axis1 and axis2 swapped. If axis1 == axis2, the result is an unchanged copy of m.

Notes:

  • m is not modified. To transpose in place, see pymath.transpose_inplace.
  • For higher-rank tensors only the two named axes are exchanged; all other axes keep their position.

Example:

local A = {{1, 2, 3}, {4, 5, 6}}   -- 2 x 3
local T = pymath.transpose(A)
-- T == {{1, 4}, {2, 5}, {3, 6}}   -- 3 x 2

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.transpose_inplace, pymath.dot

Clone this wiki locally