# numpy.identity () in Python

| |

numpy.identity (n, dtype = None): return the identity matrix, that is, the square matrix with ones on the main daignol.
Parameters :

`  n:  [int] Dimension nxn of output array  dtype:  [optional, float (by Default)] Data type of returned array. `

Returns :

` identity array of dimension nxn, with its main diagonal set to one, and all other elements 0. `

` `

` # Python Programming Illustrative # numpy.identity method   import numpy as geek   Matrix # 2x2 with 1 on the main diagnosis b = geek.identity ( 2 , dtype = float ) print ( "Matrix b: " , b)      a = geek.identity ( 4 ) print ( " Matrix a: " , a) `

` `

Output:

` Matrix b: [[1. 0.] [0. 1.]] Matrix a: [[1. 0. 0. 0.] [0. 1. 0. 0.] [0. 0. 1. 0.] [0. 0. 0. 1.]] `

Notes:
These codes will not work for online IDs. Please run them on your systems to see how they work.

## Shop Learn programming in R: courses

\$ Best Python online courses for 2022

\$ Best laptop for Fortnite

\$ Best laptop for Excel

\$ Best laptop for Solidworks

\$ Best laptop for Roblox

\$ Best computer for crypto mining

\$ Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method