Bird
0
0

What does this code output?

medium📝 Predict Output Q5 of 15
NumPy - Fundamentals
What does this code output?
import numpy as np
arr = np.array([[1, 2], [3, 4]])
print(arr.shape)
A(4,)
BError: no attribute 'shape'
C[2, 2]
D(2, 2)
Step-by-Step Solution
Solution:
  1. Step 1: Understand shape attribute

    arr.shape returns a tuple with the dimensions of the array.
  2. Step 2: Identify array dimensions

    arr is 2 rows by 2 columns, so shape is (2, 2).
  3. Final Answer:

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

    Array shape attribute = B [OK]
Quick Trick: Use .shape to get array dimensions as tuple [OK]
Common Mistakes:
  • Confusing shape with size (total elements)
  • Expecting list instead of tuple
  • Assuming shape is a method, not attribute

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes