Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Creating Arrays
What will be the output of this code?
import numpy as np
print(np.eye(2, 3, k=-1))
A[[0. 1. 0.] [0. 0. 1.]]
B[[0. 0. 0.] [0. 1. 0.]]
C[[0. 0. 0.] [1. 0. 0.]]
D[[1. 0. 0.] [0. 0. 0.]]
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.eye(2,3,k=-1)

    This creates a 2x3 matrix with ones on the diagonal shifted one below the main diagonal.
  2. Step 2: Place ones accordingly

    First row has zeros, second row has 1 at column 0 (one below main diagonal).
  3. Final Answer:

    [[0. 0. 0.] [1. 0. 0.]] -> Option C
  4. Quick Check:

    Negative k shifts diagonal down [OK]
Quick Trick: Negative k shifts diagonal down by k rows [OK]
Common Mistakes:
  • Placing ones on main diagonal
  • Misplacing ones in wrong columns
  • Confusing negative k with positive

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes