eye

Contents

eye#

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

Return a 2-D identity-like quantity or array with ones on the diagonal.

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

  • M (int | None) – Number of columns in the output. If None, defaults to N.

  • k (int) – Index of the diagonal: 0 (the default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.

  • dtype (str | type[Any] | dtype | SupportsDType | None) – Data-type of the returned array.

  • unit (saiunit.Unit) – Unit of the returned Quantity. When UNITLESS (the default) a plain array is returned.

Returns:

out – An array of shape (N, M) where all elements are zero except for the k-th diagonal, whose values are one (optionally carrying unit).

Return type:

Array | saiunit.Quantity

Examples

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