Bird
0
0

Which of the following is the correct syntax to slice a NumPy array arr to get every 3rd element from index 1 to 10?

easy📝 Syntax Q12 of 15
NumPy - Indexing and Slicing
Which of the following is the correct syntax to slice a NumPy array arr to get every 3rd element from index 1 to 10?
A<code>arr[10:1:3]</code>
B<code>arr[1:3:10]</code>
C<code>arr[1:10:3]</code>
D<code>arr[3:1:10]</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall slice order

    The slice syntax is arr[start:stop:step]. Here, start=1, stop=10, step=3 means from index 1 up to 9, every 3rd element.
  2. Step 2: Check each option

    arr[1:10:3] matches the correct order and values. Others have wrong order or values that don't match the requirement.
  3. Final Answer:

    arr[1:10:3] -> Option C
  4. Quick Check:

    Correct slice syntax = D [OK]
Quick Trick: Remember slice is start:stop:step in order [OK]
Common Mistakes:
  • Mixing up stop and step positions
  • Using step as stop index
  • Reversing start and stop incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes