Bird
0
0

What is the output shape of the following code?

medium📝 Predict Output Q4 of 15
NumPy - Array Manipulation
What is the output shape of the following code?
import numpy as np
arr = np.zeros((3, 4, 5))
transposed = arr.transpose(1, 0, 2)
print(transposed.shape)
A(4, 5, 3)
B(5, 4, 3)
C(3, 4, 5)
D(4, 3, 5)
Step-by-Step Solution
Solution:
  1. Step 1: Understand original shape

    Original array shape is (3, 4, 5).
  2. Step 2: Apply transpose with axes (1, 0, 2)

    Axes order changes to (axis 1, axis 0, axis 2) = (4, 3, 5).
  3. Final Answer:

    (4, 3, 5) -> Option D
  4. Quick Check:

    Transpose axes reorder shape accordingly [OK]
Quick Trick: Transpose axes reorder shape as per given tuple [OK]
Common Mistakes:
  • Confusing axis order
  • Assuming default transpose
  • Mixing up axis indices

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes