nlcpy.identity

nlcpy.identity(n, dtype=None)[source]

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

Parameters
nint

Number of rows (and columns) in n x n output.

dtypedtype, optional

Data-type of the output. Defaults to nlcpy.float64.

Returns
outndarray

n x n array with its main diagonal set to 1, and all other elements 0.

Examples

>>> import nlcpy as vp
>>> vp.identity(3)
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])