Bird
0
0

Given arr = np.array([10, 20, 30, 40, 50, 60, 70]), what is the output of arr[1:6:2]?

medium📝 Predict Output Q13 of 15
NumPy - Indexing and Slicing
Given arr = np.array([10, 20, 30, 40, 50, 60, 70]), what is the output of arr[1:6:2]?
A[10 30 50 70]
B[20 30 40 50 60]
C[30 50]
D[20 40 60]
Step-by-Step Solution
Solution:
  1. Step 1: Identify slice indices

    The slice arr[1:6:2] starts at index 1 (value 20), stops before index 6, stepping by 2.
  2. Step 2: Select elements

    Indexes selected: 1 (20), 3 (40), 5 (60). So output is [20 40 60].
  3. Final Answer:

    [20 40 60] -> Option D
  4. Quick Check:

    Elements at 1,3,5 = [20 40 60] [OK]
Quick Trick: Pick elements at start, start+step, ... until stop-1 [OK]
Common Mistakes:
  • Including stop index element
  • Using wrong step size
  • Starting from index 0 instead of 1

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes