Skip to content

pymath.transpose_inplace

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

Exchanges two axes of m in place and returns m. Like pymath.transpose, but does not allocate a new tensor.

This function is located in the pymath module.

m = pymath.transpose_inplace(m [, axis1 [, axis2]])

Because the swap is performed inside m, the two exchanged axes must have the same size.

Parameter Type Description
m tensor Input tensor of rank ≥ 2; transposed in place.
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
m The same table passed in, now transposed (returned for convenience).

Notes:

  • axis1 and axis2 must address axes of equal size, otherwise an error is raised. For a non-square (shape-changing) transpose, use pymath.transpose.
  • If axis1 == axis2, m is left unchanged.
  • nil holes in m are filled with 0.0.

Example:

local M = {{1, 2}, {3, 4}}
pymath.transpose_inplace(M)
-- M == {{1, 3}, {2, 4}}

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.transpose

Clone this wiki locally