Bird
0
0

Why does arr[5:2:-1] return elements in reverse order from index 5 down to 3, but arr[5:2:1] returns an empty array?

hard📝 Conceptual Q10 of 15
NumPy - Indexing and Slicing
Why does arr[5:2:-1] return elements in reverse order from index 5 down to 3, but arr[5:2:1] returns an empty array?
ABecause stop index is inclusive for negative step and exclusive for positive step.
BBecause slicing always returns empty if start > stop.
CBecause positive step requires start < stop; negative step requires start > stop.
DBecause negative step reverses array but positive step does not.
Step-by-Step Solution
Solution:
  1. Step 1: Understand step sign rules

    Positive step slices forward and requires start index less than stop index.
  2. Step 2: Negative step slices backward

    Negative step slices backward and requires start index greater than stop index.
  3. Final Answer:

    Because positive step requires start < stop; negative step requires start > stop. -> Option C
  4. Quick Check:

    Step sign controls slice direction and index order [OK]
Quick Trick: Step sign must match start-stop order for valid slice [OK]
Common Mistakes:
  • Ignoring step sign effect
  • Assuming stop index inclusive always
  • Confusing slice direction rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes