tri

Contents

tri#

class brainunit.math.tri(N, M=None, k=0, dtype=None, unit=Unit('1'))#

Return an array with ones at and below the given diagonal and zeros elsewhere.

Parameters:
  • N (int) – Number of rows in the array.

  • M (int | None) – Number of columns in the array. By default, M is taken equal to N.

  • k (int) – The sub-diagonal at and below which the array is filled. k = 0 is the main diagonal, k < 0 is below it, and k > 0 is above. The default is 0.

  • dtype (str | type[Any] | dtype | SupportsDType | None) – Data type of the returned array. The default is float.

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

Returns:

out – Array of shape (N, M) with its lower triangle filled with ones and zero elsewhere; i.e. T[i, j] == 1 for j <= i + k, 0 otherwise.

Return type:

Array | saiunit.Quantity

Examples

>>> import saiunit as u
>>> u.math.tri(3)
Array([[1., 0., 0.],
       [1., 1., 0.],
       [1., 1., 1.]], dtype=float32)
>>> u.math.tri(2, 3, unit=u.meter)
Quantity([[1. 0. 0.]
          [1. 1. 0.]], "m")