trilu#

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

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

note::

The upper triangular part of the matrix is defined as the elements on and above the specified diagonal k. The lower triangular part of the matrix is defined as the elements on and below the specified diagonal k.

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

  • k (int, default: 0) – diagonal below or 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.

  • upper (bool, default: True) – indicates whether upper or lower part of matrix is retained. Default: True.

  • 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 upper or lower triangular part(s). The returned array must have the same shape and data type as x. All elements below or above the specified diagonal k must be zeroed. The returned array should be allocated on the same device as x.

  • 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.trilu(self, /, *, k=0, upper=True, out=None)[source]#

ivy.Array instance method variant of ivy.trilu. This method simply wraps the function, and so the docstring for ivy.trilu 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 below or 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.

  • upper (bool, default: True) – indicates whether upper or lower part of matrix is retained. Default: True.

  • 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 upper triangular part(s). The returned array must have the same shape and data type as self. All elements below the specified diagonal k must be zeroed. The returned array should be allocated on the same device as self.

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

Container