Bird
0
0

What effect does inserting np.newaxis have when indexing a numpy array?

easy📝 Conceptual Q1 of 15
NumPy - Array Manipulation
What effect does inserting np.newaxis have when indexing a numpy array?
AIt removes a dimension from the array
BIt adds a new dimension to the array at the specified position
CIt changes the data type of the array elements
DIt flattens the array into 1D
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.newaxis

    np.newaxis is used to increase the dimensionality of an array by one dimension at the position where it is inserted.
  2. Step 2: Effect on shape

    When used inside indexing, it adds a new axis, changing the shape but not the data.
  3. Final Answer:

    It adds a new dimension to the array at the specified position -> Option B
  4. Quick Check:

    Adding np.newaxis increases dimensions [OK]
Quick Trick: np.newaxis adds a dimension, does not remove or flatten [OK]
Common Mistakes:
  • Thinking np.newaxis removes dimensions
  • Assuming it changes data type
  • Confusing it with flattening

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes