Bird
0
0

Which of the following best describes the effect of np.expand_dims() on a NumPy array?

easy📝 Conceptual Q1 of 15
NumPy - Array Manipulation
Which of the following best describes the effect of np.expand_dims() on a NumPy array?
AIt flattens the array into a 1D array.
BIt removes all singleton dimensions from the array.
CIt inserts a new axis at the specified position, increasing the array's dimensions by one.
DIt transposes the array by swapping two axes.
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.expand_dims()

    This function adds a new axis (dimension) to the array at the specified position.
  2. Step 2: Effect on dimensions

    Adding a new axis increases the number of dimensions by one, changing the shape accordingly.
  3. Final Answer:

    It inserts a new axis at the specified position, increasing the array's dimensions by one. -> Option C
  4. Quick Check:

    Adding axis increases ndim by 1 [OK]
Quick Trick: np.expand_dims adds a new dimension at given axis [OK]
Common Mistakes:
  • Confusing expand_dims with squeeze which removes axes
  • Thinking it flattens the array
  • Assuming it transposes the array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes