triu

Contents

triu#

class brainunit.math.triu(m, k=0, unit=Unit('1'))#

Return the upper triangle of an array.

Return a copy of an array with the elements below the k-th diagonal zeroed. For arrays with ndim > 2, triu applies to the final two axes.

Parameters:
  • m (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Input array.

  • k (int) – Diagonal below which to zero elements. k = 0 is the main diagonal, k < 0 is below it, and k > 0 is above.

  • unit (saiunit.Unit) – Unit of the returned Quantity.

Returns:

out – Upper triangle of m, of the same shape and data-type as m.

Return type:

saiunit.Quantity | Array

See also

tril

lower triangle of an array

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> u.math.triu(jnp.ones((3, 3)))
Array([[1., 1., 1.],
       [0., 1., 1.],
       [0., 0., 1.]], dtype=float32)