NumPy - BroadcastingWhy 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 dimensionBBecause data types must be identical for broadcastingCBecause arrays with different sizes cannot be addedDBecause NumPy only supports broadcasting for 1D arraysCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand broadcasting conceptDimension 1 acts like a single value repeated to match the other dimension.Step 2: Explain why other differences failIf neither dimension is 1 and sizes differ, arrays cannot align element-wise.Final Answer:Because dimension 1 can be stretched to match the other dimension -> Option AQuick 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 compatibilityThinking broadcasting only works for 1D arraysAssuming arrays with different sizes always error
Master "Broadcasting" in NumPy9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More NumPy Quizzes Array Data Types - Why dtypes matter for performance - Quiz 13medium Array Data Types - Float types (float16, float32, float64) - Quiz 13medium Array Manipulation - np.newaxis for adding dimensions - Quiz 3easy Array Operations - Comparison operations - Quiz 8hard Creating Arrays - Why array creation matters - Quiz 14medium Creating Arrays - np.ones() for one-filled arrays - Quiz 7medium Creating Arrays - np.ones() for one-filled arrays - Quiz 6medium Creating Arrays - np.linspace() for evenly spaced arrays - Quiz 2easy Indexing and Slicing - Slicing with start:stop:step - Quiz 10hard Indexing and Slicing - Boolean indexing - Quiz 8hard