Bird
0
0

You have a 2D numpy array arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]). What does arr[-1, -2] return?

hard📝 Application Q15 of 15
NumPy - Indexing and Slicing
You have a 2D numpy array arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]). What does arr[-1, -2] return?
A8
B7
C6
D9
Step-by-Step Solution
Solution:
  1. Step 1: Understand negative indexing in 2D arrays

    For rows, -1 means last row: [7, 8, 9]. For columns, -2 means second last column.
  2. Step 2: Identify element at arr[-1, -2]

    Last row is [7, 8, 9], second last column is element 8.
  3. Final Answer:

    8 -> Option A
  4. Quick Check:

    arr[-1, -2] = 8 [OK]
Quick Trick: Negative indexes count from end in each dimension [OK]
Common Mistakes:
  • Mixing row and column indexes
  • Using positive indexes instead of negative
  • Confusing which axis negative index applies to

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes