0
0
NumPydata~5 mins

np.eye() for identity matrices in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the function np.eye(n) do in NumPy?
It creates an identity matrix of size n x n. This matrix has 1s on the diagonal and 0s elsewhere.
Click to reveal answer
beginner
How can you create a 4x4 identity matrix using np.eye()?
Use np.eye(4). This returns a 4 by 4 matrix with 1s on the diagonal and 0s elsewhere.
Click to reveal answer
intermediate
What is the difference between np.eye(n) and np.identity(n)?
np.eye(n) can create rectangular matrices by specifying rows and columns, while np.identity(n) only creates square identity matrices of size n x n.
Click to reveal answer
intermediate
How do you create a 3x5 matrix with 1s on the diagonal using np.eye()?
Use np.eye(3, 5). This creates a matrix with 3 rows and 5 columns, with 1s on the diagonal and 0s elsewhere.
Click to reveal answer
intermediate
What parameter in np.eye() controls the diagonal offset?
The k parameter controls which diagonal to place the 1s on. k=0 is the main diagonal, k>0 is above, and k<0 is below the main diagonal.
Click to reveal answer
What does np.eye(3) produce?
AA 3x3 matrix of ones
BA 3x3 matrix of zeros
CA 3x3 identity matrix
DA 3x3 diagonal matrix with twos
How do you create a 2x4 matrix with 1s on the diagonal using np.eye()?
Anp.eye(2, 4)
Bnp.eye(4, 2)
Cnp.eye(2)
Dnp.eye(4)
What does the parameter k in np.eye(n, m, k) do?
ASets the diagonal offset where 1s are placed
BSets the number of rows
CSets the number of columns
DSets the data type
Which function only creates square identity matrices?
Anp.zeros()
Bnp.identity()
Cnp.eye()
Dnp.ones()
What will np.eye(3, 3, k=1) produce?
AA 3x3 matrix with 1s below the main diagonal
BA 3x3 identity matrix
CA 3x3 matrix of zeros
DA 3x3 matrix with 1s on the diagonal above the main diagonal
Explain how to create an identity matrix and how to adjust its size and shape using np.eye().
Think about rows, columns, and diagonal offset.
You got /4 concepts.
    Describe the difference between np.eye() and np.identity().
    Focus on shape flexibility.
    You got /3 concepts.