NumPy - Array ManipulationGiven a 3D numpy array with shape (2, 3, 4), how would you reshape it to a 2D array where each row is a flattened 3D slice?AUse arr.reshape(6, 4) to flatten first two dimensions per sliceBUse arr.reshape(2, 12) to flatten last two dimensions per sliceCUse arr.reshape(3, 8) to flatten last two dimensionsDUse arr.reshape(24, 1) to flatten entire arrayCheck Answer
Step-by-Step SolutionSolution:Step 1: Calculate total elements per sliceEach slice has shape (3, 4) with 12 elements.Step 2: Reshape to 2DReshape to (2, 12) makes 2 rows, each a flattened slice.Final Answer:Use arr.reshape(2, 12) to flatten last two dimensions per slice -> Option BQuick Check:Flatten slices = reshape(2, 12) [OK]Quick Trick: Flatten last dims per slice with reshape(2, 12) [OK]Common Mistakes:Mixing dimension orderFlattening wrong axesUsing incompatible shapes
Master "Array Manipulation" in NumPy9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More NumPy Quizzes Aggregation Functions - np.min() and np.max() - Quiz 3easy Aggregation Functions - Aggregation along specific axes - Quiz 9hard Array Data Types - Type casting with astype() - Quiz 6medium Array Manipulation - flatten() and ravel() for 1D conversion - Quiz 9hard Array Manipulation - np.expand_dims() and np.squeeze() - Quiz 8hard Array Manipulation - flatten() and ravel() for 1D conversion - Quiz 11easy Array Operations - Logical operations (and, or, not) - Quiz 4medium Array Operations - Comparison operations - Quiz 11easy Creating Arrays - np.array() from Python lists - Quiz 6medium NumPy Fundamentals - ndarray as the core data structure - Quiz 4medium