NumPy - BroadcastingWhy does NumPy allow broadcasting when one dimension is 1 but not when dimensions differ and neither is 1?ABecause data types must matchBBecause dimensions must always be equalCBecause arrays must have same number of elementsDBecause dimension 1 can be stretched to match the otherCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand broadcasting rule for dimension 1A dimension of size 1 can be repeated to match the other dimension size.Step 2: Explain why differing dimensions without 1 failIf neither dimension is 1 and sizes differ, they cannot be stretched to match, so broadcasting fails.Final Answer:Dimension 1 can be stretched to match the other dimension -> Option DQuick Check:Broadcasting rule reason = C [OK]Quick Trick: Dimension 1 repeats to match other size [OK]Common Mistakes:Thinking dimensions must be equal alwaysConfusing data type with shape compatibilityAssuming element count must match exactly
Master "Broadcasting" in NumPy9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More NumPy Quizzes Aggregation Functions - np.min() and np.max() - Quiz 15hard Array Manipulation - np.vstack() and np.hstack() - Quiz 11easy Array Manipulation - np.newaxis for adding dimensions - Quiz 12easy Broadcasting - Common broadcasting patterns - Quiz 9hard Creating Arrays - np.array() from Python lists - Quiz 13medium Creating Arrays - np.random.rand() and random arrays - Quiz 11easy Indexing and Slicing - Indexing returns views not copies - Quiz 8hard Indexing and Slicing - Why indexing matters - Quiz 13medium Indexing and Slicing - Fancy indexing with integer arrays - Quiz 7medium NumPy Fundamentals - Installing and importing NumPy - Quiz 2easy