fn

triu

Tensor
triu(input: Tensor, k: int = ...)
source

Return the upper-triangular part of a 2-D-or-higher tensor.

Elements below the k-th diagonal (i.e. where j < i + k) are zeroed. Batched matrices are supported.

Parameters

inputTensor
Source tensor with ndim >= 2.
kint= 0
Diagonal offset. Positive values exclude super-diagonals, negative values include sub-diagonals.

Returns

Tensor

Tensor of the same shape as input.

Notes

Together tril and triu decompose any matrix into its strict triangles plus the chosen diagonal.

Examples

>>> import lucid
>>> A = lucid.ones(3, 3)
>>> lucid.triu(A, k=1)
Tensor([[0., 1., 1.],
        [0., 0., 1.],
        [0., 0., 0.]])