Bird
0
0

Why does arr[1, :] return a 1D array when arr is a 2D numpy array?

hard📝 Conceptual Q10 of 15
NumPy - Indexing and Slicing
Why does arr[1, :] return a 1D array when arr is a 2D numpy array?
ABecause it selects the entire array
BBecause numpy automatically flattens all arrays
CBecause slicing with ':' returns a scalar
DBecause it selects all columns in the 2nd row, reducing dimensions
Step-by-Step Solution
Solution:
  1. Step 1: Understand slicing in numpy

    arr[1, :] selects all columns in row 1.
  2. Step 2: Effect on array dimensions

    Selecting a single row with all columns returns a 1D array (row vector), reducing dimension from 2D to 1D.
  3. Final Answer:

    Because it selects all columns in the 2nd row, reducing dimensions -> Option D
  4. Quick Check:

    Slicing a single row returns 1D array [OK]
Quick Trick: Selecting one row with ':' returns 1D array [OK]
Common Mistakes:
  • Thinking it returns scalar
  • Assuming numpy flattens all arrays
  • Confusing slicing with indexing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes