NumPy - BroadcastingYou want to multiply a (3,1,4) array with a (1,5,1) array and then sum over the last axis. What is the shape of the resulting array?A(1,5)B(3,1,5)C(3,5)D(3,5,4)Check Answer
Step-by-Step SolutionSolution:Step 1: Determine broadcast shapeShapes (3,1,4) and (1,5,1) broadcast to (3,5,4).Step 2: Sum over last axisSumming over axis 2 (last axis) reduces shape from (3,5,4) to (3,5).Final Answer:(3,5) -> Option CQuick Check:Broadcast then sum last axis = (3,5) [OK]Quick Trick: Sum reduces axis, broadcast first to max shape [OK]Common Mistakes:Summing before broadcastingConfusing axis to sumIncorrect broadcast shape calculation
Master "Broadcasting" in NumPy9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More NumPy Quizzes Aggregation Functions - np.sum() and axis parameter - Quiz 7medium Array Data Types - Complex number type - Quiz 2easy Array Manipulation - np.concatenate() for joining arrays - Quiz 5medium Array Manipulation - reshape() for changing dimensions - Quiz 6medium Array Operations - Why vectorized operations matter - Quiz 6medium Creating Arrays - np.zeros() for zero-filled arrays - Quiz 8hard NumPy Fundamentals - NumPy and scientific computing ecosystem - Quiz 10hard NumPy Fundamentals - Installing and importing NumPy - Quiz 6medium NumPy Fundamentals - Why NumPy over Python lists - Quiz 5medium NumPy Fundamentals - Contiguous memory layout concept - Quiz 5medium