128
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.
- n: It represents the number of rows in the resulting matrix.
- m: It represents the number columns in the resulting matrix.
- k: It is the index of the diagonal.
- 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.]]
Next Topicnumpy.matlib.identity()