Bird
0
0

You have a 2D numpy array data of shape (4, 5). How would you extract the element in the last row and last column using indexing?

hard📝 Application Q8 of 15
NumPy - Indexing and Slicing
You have a 2D numpy array data of shape (4, 5). How would you extract the element in the last row and last column using indexing?
Adata[3, 4]
BBoth A and B
Cdata[4, 5]
Ddata[-1, -1]
Step-by-Step Solution
Solution:
  1. Step 1: Understand array shape and indexing

    Shape (4,5) means rows 0-3 and columns 0-4.
  2. Step 2: Identify valid indices for last row and column

    Last row is index 3 or -1, last column is index 4 or -1.
  3. Step 3: Check options

    data[3, 4] uses positive indices, data[-1, -1] uses negative indices, both valid. data[4, 5] is out of range.
  4. Final Answer:

    Both A and B -> Option B
  5. Quick Check:

    Negative indices count from end, positive from start [OK]
Quick Trick: Use negative indices to access elements from the end [OK]
Common Mistakes:
  • Using out-of-range indices
  • Not knowing negative indexing
  • Confusing row and column order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes