Bird
0
0

What kind of matrix does np.eye(n) generate in NumPy?

easy📝 Conceptual Q1 of 15
NumPy - Creating Arrays
What kind of matrix does np.eye(n) generate in NumPy?
AA matrix filled with zeros of size n x n
BAn identity matrix of size n x n
CA matrix filled with ones of size n x n
DA diagonal matrix with random values
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.eye()

    The function np.eye(n) creates a 2D array with ones on the main diagonal and zeros elsewhere.
  2. Step 2: Matrix type

    This is the definition of an identity matrix of size n x n.
  3. Final Answer:

    An identity matrix of size n x n -> Option B
  4. Quick Check:

    Check diagonal elements are 1 and others 0 [OK]
Quick Trick: np.eye(n) creates identity matrix with ones on diagonal [OK]
Common Mistakes:
  • Confusing np.eye() with np.ones()
  • Assuming np.eye() creates a zero matrix
  • Thinking np.eye() fills matrix with random values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes