fn
tril
→Tensortril(input: Tensor, k: int = ...)Return the lower-triangular part of a 2-D-or-higher tensor.
Elements above the k-th diagonal (i.e. where j > i + k) are
zeroed out. Batched matrices are supported — the operation is
applied independently to each trailing 2-D slice.
Parameters
inputTensorSource tensor with
ndim >= 2.kint= 0Diagonal offset.
0 keeps the main diagonal; positive values
keep additional super-diagonals; negative values exclude
sub-diagonals.Returns
TensorTensor of the same shape as input.
Notes
The complementary upper-triangular extraction is triu. Note
that input need not be square.
Examples
>>> import lucid
>>> A = lucid.ones(3, 3)
>>> lucid.tril(A)
Tensor([[1., 0., 0.],
[1., 1., 0.],
[1., 1., 1.]])