Bird
0
0

What will this code print?

medium📝 Predict Output Q5 of 15
NumPy - Fundamentals
What will this code print?
import numpy as np
arr = np.array([[1, 2], [3, 4]])
print(arr.shape)
A(1, 4)
B(4,)
CError
D(2, 2)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the array shape

    The array is a 2x2 matrix with two rows and two columns.
  2. Step 2: Check the shape attribute

    arr.shape returns a tuple with (rows, columns), which is (2, 2).
  3. Final Answer:

    (2, 2) -> Option D
  4. Quick Check:

    Array shape = (2, 2) [OK]
Quick Trick: Shape shows rows and columns count [OK]
Common Mistakes:
  • Confusing shape with size
  • Expecting flat shape tuple
  • Misreading nested list structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes