Trusted answers to developer questions

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The ** identity() function** from

`numpy`

library is used to return the identity matrix.Note: An

identity matrixis the type of matrix in which all the elements on the main diagonal are ones (1) and all other elements are zeros (0).

```
identity(n, dtype=float, like=None)
```

The `identity()`

function takes the following parameter values:

: This represents the number of rows in the output.`n`

: This represents the data type of the output matrix. This is optional and its default type is float.`dtype`

: This represents the matrix-like object or the prototype.`like`

The `identity()`

function returns a square identity of $n$ by $n$ with its main or principal diagonal set to `1`

and all other elements to `0`

.

from numpy import identity# creating an identity matrix with four rowsidentity_matrix = identity(4)print(identity_matrix)

**Line 1**: We import`identity()`

from the`numpy`

module.**Line 4**: Using the`identity()`

function, we create an identity matrix with`4`

rows. The output is stored in the variable`identity_matrix`

.**Line 6**: We print the variable`identity_matrix`

.

RELATED TAGS

numpy

python

identity()

communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Keep Exploring

Related Courses