Bird
0
0

Given a = np.array([1,2,3]) and b = np.array([[10],[20],[30]]), what is the shape of a + b?

medium📝 Predict Output Q5 of 15
NumPy - Broadcasting
Given a = np.array([1,2,3]) and b = np.array([[10],[20],[30]]), what is the shape of a + b?
A(3,3)
B(3,1)
C(1,3)
D(3,)
Step-by-Step Solution
Solution:
  1. Step 1: Check shapes

    a has shape (3,), b has shape (3,1).
  2. Step 2: Broadcast shapes

    Broadcasting (3,) to (1,3), then b (3,1) to (3,3). Result shape is (3,3).
  3. Final Answer:

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

    Broadcast result shape = (3,3) [OK]
Quick Trick: 1D arrays broadcast to match 2D shapes [OK]
Common Mistakes:
  • Assuming shape stays (3,)
  • Ignoring broadcasting to 2D
  • Confusing row and column shapes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes