triu¶
- triu(x: array, /, *, k: int = 0) array ¶
Returns 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 (array) – input array having shape
(..., M, N)
and whose innermost two dimensions formMxN
matrices.k (int) –
diagonal below which to zero elements. If
k = 0
, the diagonal is the main diagonal. Ifk < 0
, the diagonal is below the main diagonal. Ifk > 0
, the diagonal is above the main diagonal. Default:0
.Note
The main diagonal is defined as the set of indices
{(i, i)}
fori
on the interval[0, min(M, N) - 1]
.
- Returns:
out (array) – 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 diagonalk
must be zeroed. The returned array should be allocated on the same device asx
.