Tril
tril(input, diagonal=0, out=NULL) -> Tensor
Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices
input
, the other elements of the result tensor out
are set to 0.
The lower triangular part of the matrix is defined as the elements on and below the diagonal.
The argument diagonal
controls which diagonal to consider. If
diagonal
= 0, all elements on and below the main diagonal are
retained. A positive value includes just as many diagonals above the main
diagonal, and similarly a negative value excludes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
\(\lbrace (i, i) \rbrace\) for \(i \in [0, \min\{d_{1}, d_{2}\} - 1]\) where
\(d_{1}, d_{2}\) are the dimensions of the matrix.
Examples
if (torch_is_installed()) {
a = torch_randn(c(3, 3))
a
torch_tril(a)
b = torch_randn(c(4, 6))
b
torch_tril(b, diagonal=1)
torch_tril(b, diagonal=-1)
}
#> torch_tensor
#> 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> 1.8172 0.0000 0.0000 0.0000 0.0000 0.0000
#> -0.2900 -0.3578 0.0000 0.0000 0.0000 0.0000
#> 0.8494 -0.3954 0.7822 0.0000 0.0000 0.0000
#> [ CPUFloatType{4,6} ]