Javatpoint Logo
Javatpoint Logo

numpy.matlib.eye()

This function returns a matrix with the diagonal elements initialized to 1 and zero elsewhere.

Syntax

Parameters

It accepts the following parameters.

  1. n: It represents the number of rows in the resulting matrix.
  2. m: It represents the number columns in the resulting matrix.
  3. k: It is the index of the diagonal.
  4. dtype: It is the data type of the output.

Return

A matrix with uninitialized entries is returned.

Example

Output:

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

Example: Initializing float values

Output:

[[1. 0. 0.]
 [0. 1. 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