Bird
0
0

Which slice will select every second element from a NumPy array arr starting from the first element?

easy📝 Conceptual Q2 of 15
NumPy - Indexing and Slicing
Which slice will select every second element from a NumPy array arr starting from the first element?
Aarr[::2]
Barr[1::2]
Carr[2::2]
Darr[:2]
Step-by-Step Solution
Solution:
  1. Step 1: Understand slice notation for step

    Using arr[::2] means start at index 0, go to the end, and take every 2nd element.
  2. Step 2: Compare options

    arr[1::2] starts at index 1, not 0. arr[2::2] starts at index 2. arr[:2] only takes first two elements.
  3. Final Answer:

    arr[::2] -> Option A
  4. Quick Check:

    Start at 0, step 2 = arr[::2] [OK]
Quick Trick: Use arr[::step] to start from first element with step [OK]
Common Mistakes:
  • Starting at wrong index
  • Using wrong step value
  • Confusing slice end with step

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes