triu#
- ivy.triu(x, /, *, k=0, out=None)[source]#
Return the upper triangular part of a matrix (or a stack of matrices)
x
.Note
The upper triangular part of the matrix is defined as the elements on and above the specified diagonal
k
.- Parameters:
x (
Union
[Array
,NativeArray
]) – input array having shape (…, M, N) and whose innermost two dimensions form MxN matrices. *,k (
int
, default:0
) – diagonal below which to zero elements. If k = 0, the diagonal is the main diagonal. If k < 0, the diagonal is below the main diagonal. If k > 0, the diagonal is above the main diagonal. Default:0
.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 upper triangular part(s). The returned array must have the same shape and data type as x. All elements below the specified diagonal k must be zeroed. The returned array should be allocated on the same device as x.
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.
- Array.triu(self, /, *, k=0, out=None)[source]#
ivy.Array instance method variant of ivy.triu. This method simply wraps the function, and so the docstring for ivy.triu also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array having shape (…, M, N) and whose innermost two dimensions form MxN matrices. *,k (
int
, default:0
) – diagonal below which to zero elements. If k = 0, the diagonal is the main diagonal. If k < 0, the diagonal is below the main diagonal. If k > 0, the diagonal is above the main diagonal. Default:0
.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 upper triangular part(s). The returned array must have the same shape and data type as
self
. All elements below the specified diagonal k must be zeroed. The returned array should be allocated on the same device asself
.