Bird
0
0

You have a numpy array arr = np.array([10, 20, 30, 40, 50, 60]). How do you extract the last three elements using negative indexing?

hard📝 Application Q8 of 15
NumPy - Indexing and Slicing
You have a numpy array arr = np.array([10, 20, 30, 40, 50, 60]). How do you extract the last three elements using negative indexing?
Aarr[:3]
Barr[3:]
Carr[-6:-3]
Darr[-3:]
Step-by-Step Solution
Solution:
  1. Step 1: Understand slicing with negative indexes

    arr[-3:] means slice from third last element to end.
  2. Step 2: Check which elements arr[-3:] returns

    It returns [40, 50, 60], the last three elements.
  3. Final Answer:

    arr[-3:] -> Option D
  4. Quick Check:

    Last three elements slice = arr[-3:] [OK]
Quick Trick: Use arr[-n:] to get last n elements [OK]
Common Mistakes:
  • Using arr[:3] which gets first three
  • Using arr[3:] which gets last three but not negative index
  • Using wrong slice boundaries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes