Bird
0
0

Why does NumPy allow broadcasting when one dimension is 1 but not when dimensions differ and neither is 1?

hard📝 Conceptual Q10 of 15
NumPy - Broadcasting
Why does NumPy allow broadcasting when one dimension is 1 but not when dimensions differ and neither is 1?
ABecause arrays with different sizes cannot be used together
BBecause dimensions must always be equal for operations
CBecause broadcasting only works for 1D arrays
DBecause dimension 1 can be stretched to match the other dimension without copying data
Step-by-Step Solution
Solution:
  1. Step 1: Understand broadcasting mechanics

    Dimension size 1 can be virtually repeated to match the other dimension without extra memory.
  2. Step 2: Contrast with incompatible dimensions

    If neither dimension is 1 and sizes differ, no safe broadcasting is possible.
  3. Final Answer:

    Because dimension 1 can be stretched to match the other dimension without copying data -> Option D
  4. Quick Check:

    Dimension 1 allows virtual stretching [OK]
Quick Trick: Dimension 1 stretches without copying [OK]
Common Mistakes:
  • Thinking all different sizes broadcast
  • Assuming broadcasting copies data
  • Believing broadcasting is only for 1D arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes