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:
Step 1: Understand numpy's broadcasting alignment
Broadcasting compares array shapes from the last dimension backward to align elements properly.
Step 2: Explain why right alignment matters
This ensures smaller arrays can be expanded along leading dimensions without ambiguity.
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.
Final Answer:
Because numpy aligns arrays from the right to match shapes for element-wise operations -> Option C
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
Master "Broadcasting" in NumPy
9 interactive learning modes - each teaches the same concept differently