Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q13 of 15
NumPy - Fundamentals

What will be the output of the following code?

import numpy as np
arr = np.array([[1, 2], [3, 4]])
print(arr.shape)
A(4,)
B(2, 2)
C(1, 4)
D(2,)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the array shape

    The array has 2 rows and 2 columns, so shape is (2, 2).
  2. Step 2: Check print output

    arr.shape returns a tuple with dimensions, so output is (2, 2).
  3. Final Answer:

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

    2 rows and 2 columns = (2, 2) [OK]
Quick Trick: Shape shows rows and columns as tuple [OK]
Common Mistakes:
  • Confusing shape with total elements
  • Expecting a list instead of tuple
  • Mixing up rows and columns count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes