Bird
0
0

Which of the following is the correct syntax to add a new axis at position 0 using np.expand_dims() on array arr?

easy📝 Syntax Q3 of 15
NumPy - Array Manipulation
Which of the following is the correct syntax to add a new axis at position 0 using np.expand_dims() on array arr?
Anp.expand_dims(arr, axis=arr.shape[0])
Bnp.expand_dims(arr, axis=1)
Cnp.expand_dims(arr, axis=-1)
Dnp.expand_dims(arr, axis=0)
Step-by-Step Solution
Solution:
  1. Step 1: Recall axis parameter meaning

    The axis parameter specifies where the new axis is inserted. Position 0 means before the first dimension.
  2. Step 2: Match syntax to position

    Using axis=0 adds the new axis at the start. Other options add it elsewhere or cause errors.
  3. Final Answer:

    np.expand_dims(arr, axis=0) -> Option D
  4. Quick Check:

    axis=0 adds new axis at front [OK]
Quick Trick: axis=0 adds axis at front, axis=-1 adds at end [OK]
Common Mistakes:
  • Using wrong axis number
  • Confusing axis with shape index
  • Using axis beyond array dimensions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes