NumPy - BroadcastingYou have arrays with shapes (7, 1, 5) and (1, 3, 1). You want to add them using broadcasting. What will be the resulting shape?A(1, 3, 5)B(7, 1, 1)C(7, 3, 5)DCannot broadcast these shapesCheck Answer
Step-by-Step SolutionSolution:Step 1: Compare shapes from right to leftRight dims: 5 and 1, 1 broadcasts to 5. Middle dims: 1 and 3, 1 broadcasts to 3. Left dims: 7 and 1, 1 broadcasts to 7.Step 2: Combine broadcasted dimensionsResulting shape is (7, 3, 5) taking max of each dimension.Final Answer:(7, 3, 5) -> Option CQuick Check:Broadcast dims max or 1 expands [OK]Quick Trick: Broadcast dims max or 1 expands to max [OK]Common Mistakes:Mixing up dimension orderAssuming shapes must be identicalForgetting 1 can broadcast to any size
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