tril#

ivy.tril(x, /, *, k=0, out=None)[source]#

Return the lower triangular part of a matrix (or a stack of matrices) x.

Note

The main diagonal is defined as the set of indices {(i, i)} for i on the interval [0, min(M, N) - 1].

Parameters:
  • x (Union[Array, NativeArray]) – input array having shape (…, M, N) and whose innermost two dimensions form MxN matrices.

  • k (int, default: 0) – diagonal above which to zero elements. If k = 0, the diagonal is the main diagonal. If k < 0, the diagonal is below the main diagonal. If k > 0, the diagonal is above the main diagonal. Default: 0.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the lower triangular part(s). The returned array must have the same shape and data type as x. All elements above the specified diagonal k must be zeroed. The returned array should be allocated on the same device as x.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Array.tril(self, /, *, k=0, out=None)[source]#

ivy.Array instance method variant of ivy.tril. This method simply wraps the function, and so the docstring for ivy.tril also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array having shape (…, M, N) and whose innermost two dimensions form MxN matrices.

  • k (int, default: 0) – diagonal above which to zero elements. If k = 0, the diagonal is the main diagonal. If k < 0, the diagonal is below the main diagonal. If k > 0, the diagonal is above the main diagonal. Default: 0.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the lower triangular part(s). The returned array must have the same shape and data type as self. All elements above the specified diagonal k must be zeroed. The returned array should be allocated on the same device as self.

Container.tril(self, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, k=0, out=None)[source]#
Return type:

Container