114
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.
- shape: It is the number of rows and columns in the resulting identity matrix.
- 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]]
Next Topicnumpy.matlib.ones()