Bird
0
0

Given a 3D NumPy array arr with shape (2, 3, 4), which transpose() call will reorder the axes so that the second axis is first, the third axis is second, and the first axis is last?

hard📝 Application Q9 of 15
NumPy - Array Manipulation
Given a 3D NumPy array arr with shape (2, 3, 4), which transpose() call will reorder the axes so that the second axis is first, the third axis is second, and the first axis is last?
Aarr.transpose(2, 1, 0)
Barr.transpose(1, 2, 0)
Carr.transpose(0, 2, 1)
Darr.transpose(2, 0, 1)
Step-by-Step Solution
Solution:
  1. Step 1: Understand original axes

    Original shape is (2, 3, 4) corresponding to axes 0, 1, 2.
  2. Step 2: Desired order

    Second axis (1) first, third axis (2) second, first axis (0) last.
  3. Step 3: Apply transpose

    Use arr.transpose(1, 2, 0) to reorder axes accordingly.
  4. Final Answer:

    arr.transpose(1, 2, 0) -> Option B
  5. Quick Check:

    Check new shape is (3, 4, 2) [OK]
Quick Trick: Transpose axes in desired order as tuple [OK]
Common Mistakes:
  • Mixing up axis indices
  • Using default transpose which reverses axes
  • Passing incorrect tuple order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes