Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q13 of 15
SciPy - Basics and Scientific Computing
What will be the output of the following code?
import numpy as np
arr = np.array([[1, 2], [3, 4]])
print(arr.shape)
A(2, 2)
B(4,)
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: Confirm shape output

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

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

    2 rows and 2 columns = (2, 2) [OK]
Quick Trick: Shape shows (rows, columns) for 2D arrays [OK]
Common Mistakes:
MISTAKES
  • Confusing total elements with shape
  • Expecting a flat tuple like (4,)
  • Misreading rows and columns order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes