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 data types must match
BBecause dimensions must always be equal
CBecause arrays must have same number of elements
DBecause dimension 1 can be stretched to match the other
Step-by-Step Solution
Solution:
  1. Step 1: Understand broadcasting rule for dimension 1

    A dimension of size 1 can be repeated to match the other dimension size.
  2. Step 2: Explain why differing dimensions without 1 fail

    If neither dimension is 1 and sizes differ, they cannot be stretched to match, so broadcasting fails.
  3. Final Answer:

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

    Broadcasting rule reason = C [OK]
Quick Trick: Dimension 1 repeats to match other size [OK]
Common Mistakes:
  • Thinking dimensions must be equal always
  • Confusing data type with shape compatibility
  • Assuming element count must match exactly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes