Challenge - 5 Problems
Identity Matrix Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of np.eye() with default parameters
What is the output of this code snippet?
import numpy as np print(np.eye(3))
NumPy
import numpy as np print(np.eye(3))
Attempts:
2 left
💡 Hint
np.eye(n) creates an n x n matrix with 1s on the main diagonal and 0s elsewhere.
✗ Incorrect
np.eye(3) creates a 3x3 identity matrix with 1.0 on the diagonal and 0.0 elsewhere.
❓ Predict Output
intermediate2:00remaining
Effect of k parameter in np.eye()
What is the output of this code?
import numpy as np print(np.eye(4, k=1))
NumPy
import numpy as np print(np.eye(4, k=1))
Attempts:
2 left
💡 Hint
The k parameter shifts the diagonal by k positions above (positive) or below (negative) the main diagonal.
✗ Incorrect
k=1 shifts the diagonal of 1s one step above the main diagonal, so the 1s appear just above the main diagonal.
❓ data_output
advanced2:00remaining
Shape of np.eye() with different rows and columns
What is the shape of the array created by this code?
import numpy as np arr = np.eye(3, 5) print(arr.shape)
NumPy
import numpy as np arr = np.eye(3, 5) print(arr.shape)
Attempts:
2 left
💡 Hint
The first argument is the number of rows, the second is the number of columns.
✗ Incorrect
np.eye(3, 5) creates a matrix with 3 rows and 5 columns, so the shape is (3, 5).
❓ visualization
advanced2:00remaining
Visual pattern of np.eye() with negative k
Which option shows the correct printed output of this code?
import numpy as np print(np.eye(4, k=-1))
NumPy
import numpy as np print(np.eye(4, k=-1))
Attempts:
2 left
💡 Hint
Negative k shifts the diagonal below the main diagonal.
✗ Incorrect
k=-1 places 1s on the diagonal just below the main diagonal, so the 1s start at position (1,0).
🧠 Conceptual
expert2:00remaining
Understanding dtype effect in np.eye()
What will be the dtype and output of this code?
import numpy as np arr = np.eye(2, dtype=int) print(arr) print(arr.dtype)
NumPy
import numpy as np arr = np.eye(2, dtype=int) print(arr) print(arr.dtype)
Attempts:
2 left
💡 Hint
dtype=int forces the matrix elements to be integers instead of floats.
✗ Incorrect
np.eye with dtype=int creates an integer identity matrix. The default int type on many systems is int64.