numpy.matlib.eye()

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

Syntax

snippet
numpy.matlib.eye(n, m, k, dtype)

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

snippet
import numpy as np  
  
import numpy.matlib  
  
print(numpy.matlib.eye(n=3,m=3,k=0,dtype=int))

Output:

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

Example: Initializing float values

snippet
import numpy as np  
  
import numpy.matlib  
  
print(numpy.matlib.eye(n=3,m=3,k=0,dtype=float))

Output:

Output
[[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]]
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +