numpy.identity() in Python (original) (raw)

Last Updated : 22 Apr, 2025

numpy.identity() function is used to create an **identity matrix which is used to make identity matrix. This is commonly used in linear algebra and numerical computations. It has the following properties:

**Syntax: numpy.identity(n, dtype=None)

where:

In the below example we use numpy.identity() to create identity matrices of size 2×2 and 4×4 with 1s on the diagonal and 0s elsewhere. The dtype=float specifies that the matrix elements should be float type.

Python `

import numpy as geek

b = geek.identity(2, dtype = float) print("Matrix b : \n", b)

a = geek.identity(4) print("\nMatrix a : \n", a)

`

**Output :

Screenshot-2025-04-13-160952

Identity Matrix

It is useful for linear algebra operations like matrix multiplication, transformations and solving equations.

Similar Reads