Bird
0
0

Given arrays with shapes (2, 1, 4) and (3, 4), what is the broadcasted shape when adding them?

hard📝 Application Q9 of 15
NumPy - Broadcasting
Given arrays with shapes (2, 1, 4) and (3, 4), what is the broadcasted shape when adding them?
AError: shapes not compatible
B(2, 3, 4)
C(2, 1, 4)
D(3, 4)
Step-by-Step Solution
Solution:
  1. Step 1: Align shapes right to left

    Shapes: (2,1,4) and (3,4) align as (2,1,4) and (1,3,4).
  2. Step 2: Check compatibility and broadcast shape

    Dimensions: 4=4 equal, 1 and 3 (one is 1, compatible), 2 and 1 (one is 1, compatible). Broadcasted shape: max(2,1)=2, max(1,3)=3, 4 -> (2,3,4).
  3. Final Answer:

    The broadcasted shape is (2, 3, 4) -> Option B
  4. Quick Check:

    Broadcast shape = (2, 3, 4) [OK]
Quick Trick: Align shapes right to left; missing dims treated as 1 [OK]
Common Mistakes:
  • Assuming missing leading dims are ignored
  • Confusing dimension order
  • Assuming broadcasting always works if some dims match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes