Bird
0
0

Given arrays A with shape (5, 1, 4) and B with shape (1, 3, 1), what is the shape of the result when computing A * B? Also, explain why this shape occurs.

hard📝 Application Q9 of 15
NumPy - Broadcasting
Given arrays A with shape (5, 1, 4) and B with shape (1, 3, 1), what is the shape of the result when computing A * B? Also, explain why this shape occurs.
A(1, 3, 4) because last dimension is 4 in both
B(5, 3, 4) because dimensions broadcast by matching or expanding 1s
C(5, 1, 1) because only first dimension matches
DBroadcasting error due to incompatible shapes
Step-by-Step Solution
Solution:
  1. Step 1: Compare each dimension

    A shape: (5,1,4), B shape: (1,3,1). Dimensions broadcast if equal or one is 1.
  2. Step 2: Determine broadcasted shape

    Dimensions become max per axis: 5, 3, 4.
  3. Step 3: Explain broadcasting

    Dimensions with 1 are stretched to match the other array's size.
  4. Final Answer:

    (5, 3, 4) because dimensions broadcast by matching or expanding 1s -> Option B
  5. Quick Check:

    Broadcast shape = max dimension per axis [OK]
Quick Trick: Broadcast shape is max dimension or 1 per axis [OK]
Common Mistakes:
  • Assuming shapes must be identical
  • Ignoring dimension with size 1
  • Expecting error incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes