Bird
0
0

Which of the following commands correctly creates a 4x4 identity matrix using NumPy?

easy📝 Syntax Q3 of 15
NumPy - Creating Arrays
Which of the following commands correctly creates a 4x4 identity matrix using NumPy?
Anp.eye(3, 4)
Bnp.eye(4, 4, k=1)
Cnp.eye(4, 3)
Dnp.eye(4)
Step-by-Step Solution
Solution:
  1. Step 1: Syntax of np.eye()

    The function np.eye(N, M=None, k=0) creates an N x M matrix with ones on the k-th diagonal.
  2. Step 2: Creating a 4x4 identity matrix

    Calling np.eye(4) creates a 4x4 identity matrix with ones on the main diagonal (k=0 by default).
  3. Final Answer:

    np.eye(4) -> Option D
  4. Quick Check:

    Check shape is (4,4) and diagonal ones [OK]
Quick Trick: np.eye(n) creates n x n identity matrix by default [OK]
Common Mistakes:
  • Using k=1 shifts diagonal off main
  • Specifying mismatched rows and columns
  • Confusing np.eye() with np.identity()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes