Bird
0
0

Which of the following is the correct syntax to create a 3x5 identity matrix with 1s on the main diagonal using np.eye()?

easy📝 Syntax Q12 of 15
NumPy - Creating Arrays
Which of the following is the correct syntax to create a 3x5 identity matrix with 1s on the main diagonal using np.eye()?
A<code>np.eye(5, 3)</code>
B<code>np.eye(3, 5)</code>
C<code>np.eye(3)</code>
D<code>np.eye(5)</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.eye() parameters

    The first parameter is the number of rows, the second is columns. So np.eye(3, 5) creates a 3x5 matrix.
  2. Step 2: Check the options

    np.eye(3, 5) correctly uses np.eye(3, 5) to create a 3x5 matrix with 1s on the main diagonal.
  3. Final Answer:

    np.eye(3, 5) -> Option B
  4. Quick Check:

    np.eye(rows, cols) = correct syntax [OK]
Quick Trick: First arg = rows, second = columns in np.eye() [OK]
Common Mistakes:
  • Swapping rows and columns parameters
  • Using only one parameter for non-square matrix
  • Confusing np.eye() with np.identity()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes