colour.utilities.xp_matrix_transpose#
- colour.utilities.xp_matrix_transpose(a: ArrayLike, *, xp: ProtocolArrayNamespace | ModuleType | None = None) NDArray[source]#
Array API compatible implementation of
numpy.matrix_transpose()materialising the result to a C-contiguous array.Equivalent to
xp.matrix_transpose(a)followed byxp_ascontiguousarray(). Use whenever the transposed array will participate in subsequent broadcasts ormatmuloperations; the lazy stride-permuted view returned by the standardmatrix_transposepoisons broadcast outputs (the NumPy broadcast machinery inherits the strided layout into the freshly-allocated output) and forces BLAS to copy internally on every matmul. The cost of materialising once is amortised by keeping all downstream broadcasts and matmuls on contiguous memory.- Parameters:
a (ArrayLike) – Variable \(a\); the last two axes are swapped.
xp (ProtocolArrayNamespace | ModuleType | None) – Array namespace module. If None, derived from
a.
- Returns:
Matrix-transposed and C-contiguous array.
- Return type:
Examples
>>> a = np.arange(6).reshape(2, 3) >>> xp_matrix_transpose(a, xp=np) array([[0, 3], [1, 4], [2, 5]])