numpy.identity() in Python

The identity() method of Python numpy class returns an identity matrix i.e., a square matrix with ones on the main diagonal.



The numpy. identity()  method consists of two parameters, which are as follows:

N : It represents the number of rows(or columns).

dtype : It is an optional parameter. It depicts the data type of returned array, and by default, it is a float.

Return Value

The numpy.identity () method returns identity array of dimension n x n,  with its main diagonal set to one, and all other elements equal to zero.

Example 1


Pin It on Pinterest

Share This