matrix_transpose#
- ivy.matrix_transpose(x, /, *, conjugate=False, out=None)[source]#
Transposes a matrix (or a stack of matrices)
x
.- Parameters:
x (
Union
[Array
,NativeArray
]) – input array having shape(..., M, N)
and whose innermost two dimensions formMxN
matrices.conjugate (
bool
, default:False
) – If True, takes the conjugate of the matrix.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – an array containing the transpose for each matrix and having shape
(..., N, M)
. The returned array must have the same data type asx
.
This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.
Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.Examples
With :code: ‘ivy.Array’ inputs:
>>> x = ivy.array([[0., 2.], [1., 3.]]) >>> y = ivy.matrix_transpose(x) >>> print(y) ivy.array([[0., 1.], [2., 3.]])
>>> x = ivy.array([[1., 4.], [2., 5.], [3., 1.]]) >>> y = ivy.zeros((2, 3)) >>> ivy.matrix_transpose(x, out=y) ivy.array([[1., 2., 3.], [4., 5., 1.]])
>>> x = ivy.array([[2., 3.], [1., 2.]]) >>> ivy.matrix_transpose(x, out=x) ivy.array([[2., 1.], [3., 2.]])
>>> x = ivy.array([[0., 1., 2.], [1., 2., 3.]]) >>> y = ivy.matrix_transpose(x) >>> print(y) ivy.array([[0., 1.], [1., 2.], [2., 3.]])
With :code: ‘ivy.Container’ inputs:
>>> x = ivy.Container(a=ivy.array([[0., 1.], [0., 2.]]), b=ivy.array([[3., 4.], [3., 5.]])) >>> y = ivy.matrix_transpose(x) >>> print(y) { a: ivy.array([[0., 0.], [1., 2.]]), b: ivy.array([[3., 3.], [4., 5.]]) }
- Array.matrix_transpose(self, /, *, conjugate=False, out=None)[source]#
Transpose a matrix (or a stack of matrices)
x
.- Parameters:
self (
Array
) – input array having shape(..., M, N)
and whose innermost two dimensions formMxN
matrices.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – an array containing the transpose for each matrix and having shape
(..., N, M)
. The returned array must have the same data type asx
.
Examples
With
ivy.Array
instance inputs:>>> x = ivy.array([[1., 2.], [0., 3.]]) >>> y = x.matrix_transpose() >>> print(y) ivy.array([[1., 0.], [2., 3.]])
- Container.matrix_transpose(self, /, *, conjugate=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
Transpose a matrix (or a stack of matrices)
x
.- Parameters:
self (
Container
) – input Container which will have arrays with shape(..., M, N)
and whose innermost two dimensions formMxN
matrices.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – A container with the transposes for each matrix and having shape
(..., N, M)
. The returned array must have the same data type asx
.
Examples
With
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([[1., 1.], [0., 3.]]), b=ivy.array([[0., 4.], [3., 1.]])) >>> y = x.matrix_transpose() >>> print(y) { a: ivy.array([[1., 0.], [1., 3.]]), b: ivy.array([[0., 3.], [4., 1.]]) }