fn

tril

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

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

inputTensor
Source tensor with ndim >= 2.
kint= 0
Diagonal offset. 0 keeps the main diagonal; positive values keep additional super-diagonals; negative values exclude sub-diagonals.

Returns

Tensor

Tensor 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.]])