fn
triu
→Tensortriu(input: Tensor, k: int = ...)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
inputTensorSource tensor with
ndim >= 2.kint= 0Diagonal offset. Positive values exclude super-diagonals,
negative values include sub-diagonals.
Returns
TensorTensor 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.]])