midNumPy
What is broadcasting rule in NumPy?
Updated May 17, 2026
Short answer
Broadcasting allows arrays of different shapes to operate together under compatibility rules.
Deep explanation
NumPy compares shapes from right to left. Dimensions are compatible if equal or one of them is 1. It avoids copying data by virtually expanding arrays.
Real-world example
Adding bias vectors to batches in deep learning.
Common mistakes
- Assuming any shape mismatch works automatically.
Follow-up questions
- What happens when shapes are incompatible?
- Does broadcasting allocate memory?