numpy.eye (R, C = No, k = 0, dtype = type "& # 39; float & # 39;"): Returns a matrix with 1 on the diagonal and 0 elsewhere relative to k .
Parameters :
R: Number of rows C: [optional] Number of columns; By default M = N k: [int, optional, 0 by default] Diagonal we require; k" 0 means diagonal above main diagonal or vice versa. dtype: [optional, float (by Default)] Data type of returned array.
Returns :
array of shape, R x C, an array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one.
|
Output:
Matrix b: [[1. 0.] [0. 1.]] Matrix a: [[0. 0. 0. 0. 0 .] [1. 0. 0. 0. 0.] [0. 1. 0. 0. 0.] [0. 0. 1. 0. 0.]]
Notes :
These codes will not work for an online ID. Please run them on your systems to see how they work
This article is courtesy of Mohit Gupta_OMG