Bird
0
0

Find the mistake in this code:

medium📝 Debug Q7 of 15
NumPy - Array Manipulation
Find the mistake in this code:
import numpy as np
arr = np.array([[1, 2], [3, 4]])
transposed = np.transpose(arr, axes=2)
print(transposed)
AThe array must be 3D to use axes argument.
Baxes argument must be a tuple, not an integer.
Carr.transpose() should be used instead of np.transpose().
Dnp.transpose() cannot be used on 2D arrays.
Step-by-Step Solution
Solution:
  1. Step 1: Check axes argument type

    axes argument must be a tuple specifying the order of axes, not a single integer.
  2. Step 2: Confirm correct usage

    For 2D arrays, axes should be a tuple like (1, 0) or omitted for default transpose.
  3. Final Answer:

    axes argument must be a tuple, not an integer. -> Option B
  4. Quick Check:

    Axes must be tuple in np.transpose() [OK]
Quick Trick: Axes argument in transpose must be a tuple [OK]
Common Mistakes:
  • Passing integer instead of tuple
  • Misusing np.transpose on 2D arrays
  • Confusing method and function usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes