flopscope.numpy.matrix_transpose
fnp.matrix_transpose(x, /)[flopscope source][numpy source]
Transposes a matrix (or a stack of matrices) ``x``.
Adapted from NumPy docs np.matrix_transpose
Cost
0
Flopscope Context
Transpose last two dimensions (NumPy 2.x array API).
Transposes a matrix (or a stack of matrices) x.
This function is Array API compatible.
Parameters
- x:array_like
Input array having shape (..., M, N) and whose two innermost dimensions form
MxNmatrices.
Returns
- out:ndarray
An array containing the transpose for each matrix and having shape (..., N, M).
See also
- we.flops.transpose Generic transpose method.
Examples
>>> import flopscope.numpy as fnp
>>> flops.matrix_transpose([[1, 2], [3, 4]])
array([[1, 3],
[2, 4]])>>> flops.matrix_transpose([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
array([[[1, 3],
[2, 4]],
[[5, 7],
[6, 8]]])