Bird
0
0

Why does numpy broadcasting require that dimensions be compatible starting from the trailing dimensions?

hard📝 Conceptual Q10 of 15
NumPy - Broadcasting
Why does numpy broadcasting require that dimensions be compatible starting from the trailing dimensions?
ABecause the first dimension is always the batch size and cannot be broadcasted
BBecause numpy only supports broadcasting for 1D arrays
CBecause numpy aligns arrays from the right to match shapes for element-wise operations
DBecause broadcasting duplicates data along the first dimension only
Step-by-Step Solution
Solution:
  1. Step 1: Understand numpy's broadcasting alignment

    Broadcasting compares array shapes from the last dimension backward to align elements properly.
  2. Step 2: Explain why right alignment matters

    This ensures smaller arrays can be expanded along leading dimensions without ambiguity.
  3. Step 3: Reject incorrect options

    Broadcasting supports multi-dimensional arrays, not only 1D. First dimension can be broadcasted if compatible. Broadcasting does not duplicate data but creates views.
  4. Final Answer:

    Because numpy aligns arrays from the right to match shapes for element-wise operations -> Option C
  5. Quick Check:

    Broadcasting aligns shapes from trailing dimensions [OK]
Quick Trick: Broadcasting compares shapes from right to left [OK]
Common Mistakes:
  • Thinking broadcasting only works for 1D
  • Assuming first dimension can't broadcast
  • Believing broadcasting duplicates data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes