Bird
0
0

Given arr = np.array([1, 3, 5, 7, 9]), what does arr[-1] + arr[-5] return?

medium📝 Predict Output Q5 of 15
NumPy - Indexing and Slicing
Given arr = np.array([1, 3, 5, 7, 9]), what does arr[-1] + arr[-5] return?
A8
B10
C9
D6
Step-by-Step Solution
Solution:
  1. Step 1: Identify arr[-1] and arr[-5]

    arr[-1] is last element 9, arr[-5] is first element 1.
  2. Step 2: Calculate sum

    9 + 1 = 10.
  3. Final Answer:

    10 -> Option B
  4. Quick Check:

    arr[-1] + arr[-5] = 10 [OK]
Quick Trick: Sum last and first using negative indexes [-1 and -length] [OK]
Common Mistakes:
  • Mixing up indexes
  • Adding wrong elements
  • Forgetting negative indexing starts at -1

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes