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 dimension 1 can be stretched to match the other dimension
BBecause data types must be identical for broadcasting
CBecause arrays with different sizes cannot be added
DBecause NumPy only supports broadcasting for 1D arrays
Step-by-Step Solution
Solution:
  1. Step 1: Understand broadcasting concept

    Dimension 1 acts like a single value repeated to match the other dimension.
  2. Step 2: Explain why other differences fail

    If neither dimension is 1 and sizes differ, arrays cannot align element-wise.
  3. Final Answer:

    Because dimension 1 can be stretched to match the other dimension -> Option A
  4. Quick Check:

    Dimension 1 stretches for broadcasting, others fail [OK]
Quick Trick: Dimension 1 repeats to match other dimension in broadcasting [OK]
Common Mistakes:
  • Confusing data type with shape compatibility
  • Thinking broadcasting only works for 1D arrays
  • Assuming arrays with different sizes always error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes