identity

Contents

identity#

class saiunit.math.identity(n, dtype=None, unit=Unit('1'))#

Return the identity quantity or array.

The identity array is a square array with ones on the main diagonal.

Parameters:
  • n (int) – Number of rows (and columns) in the n x n output.

  • dtype (str | type[Any] | dtype | SupportsDType | None) – Data-type of the output. Defaults to float.

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

Returns:

outn x n array with its main diagonal set to one and all other elements zero.

Return type:

Array | saiunit.Quantity

Examples

>>> import saiunit as u
>>> u.math.identity(3)
Array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]], dtype=float32)
>>> u.math.identity(2, unit=u.second)
Quantity([[1. 0.]
          [0. 1.]], "s")