Bird
0
0

You have a 3D NumPy array arr with shape (4, 3, 2). How would you index to get all elements from the second row of every 2D slice?

hard📝 Application Q8 of 15
NumPy - Indexing and Slicing
You have a 3D NumPy array arr with shape (4, 3, 2). How would you index to get all elements from the second row of every 2D slice?
Aarr[:, :, 1]
Barr[:, 1, :]
Carr[1, :, :]
Darr[1, 1, :]
Step-by-Step Solution
Solution:
  1. Step 1: Understand array shape and indexing

    Shape (4,3,2) means 4 slices, each 3 rows and 2 columns.
  2. Step 2: Select second row (index 1) from every slice

    Use ':' for all slices, '1' for second row, ':' for all columns: arr[:, 1, :].
  3. Final Answer:

    arr[:, 1, :] -> Option B
  4. Quick Check:

    Indexing 3D array rows = arr[:, 1, :] [OK]
Quick Trick: Use ':' to select all in a dimension [OK]
Common Mistakes:
  • Mixing row and slice indices
  • Using wrong dimension for row
  • Selecting single slice instead of all

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes