Bird
0
0

You want to multiply a (3,1,4) array with a (1,5,1) array and then sum over the last axis. What is the shape of the resulting array?

hard📝 Application Q9 of 15
NumPy - Broadcasting
You want to multiply a (3,1,4) array with a (1,5,1) array and then sum over the last axis. What is the shape of the resulting array?
A(1,5)
B(3,1,5)
C(3,5)
D(3,5,4)
Step-by-Step Solution
Solution:
  1. Step 1: Determine broadcast shape

    Shapes (3,1,4) and (1,5,1) broadcast to (3,5,4).
  2. Step 2: Sum over last axis

    Summing over axis 2 (last axis) reduces shape from (3,5,4) to (3,5).
  3. Final Answer:

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

    Broadcast then sum last axis = (3,5) [OK]
Quick Trick: Sum reduces axis, broadcast first to max shape [OK]
Common Mistakes:
  • Summing before broadcasting
  • Confusing axis to sum
  • Incorrect broadcast shape calculation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes