Bird
0
0

Given 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?

hard📝 Application Q9 of 15
NumPy - Array Manipulation
Given 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 slice
BUse arr.reshape(2, 12) to flatten last two dimensions per slice
CUse arr.reshape(3, 8) to flatten last two dimensions
DUse arr.reshape(24, 1) to flatten entire array
Step-by-Step Solution
Solution:
  1. Step 1: Calculate total elements per slice

    Each slice has shape (3, 4) with 12 elements.
  2. Step 2: Reshape to 2D

    Reshape to (2, 12) makes 2 rows, each a flattened slice.
  3. Final Answer:

    Use arr.reshape(2, 12) to flatten last two dimensions per slice -> Option B
  4. Quick Check:

    Flatten slices = reshape(2, 12) [OK]
Quick Trick: Flatten last dims per slice with reshape(2, 12) [OK]
Common Mistakes:
  • Mixing dimension order
  • Flattening wrong axes
  • Using incompatible shapes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes