Javatpoint Logo
Javatpoint Logo

numpy.matlib.identity()

This function is used to return an identity matrix of the given size. An identity matrix is the one with diagonal elements initializes to 1 and all other elements to zero.

Syntax

Parameters

It accepts the following parameters.

  1. shape: It is the number of rows and columns in the resulting identity matrix.
  2. dtype: It is the data type of the identity matrix.

Return

It returns an identity matrix of the specified size and specified data type.

Example

Output:

[[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]]

Example: Identity matrix with integer values

Output:

[[1 0 0 0]
 [0 1 0 0]
 [0 0 1 0]
 [0 0 0 1]]






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA