Bird
0
0

What is the output of this code?

medium📝 Predict Output Q4 of 15
NumPy - Indexing and Slicing
What is the output of this code?
import numpy as np
arr = np.array([5, 10, 15, 20])
print(arr[1:3])
A[20]
B[5 10]
C[10 15]
D[15 20]
Step-by-Step Solution
Solution:
  1. Step 1: Understand slicing syntax arr[1:3]

    This slice selects elements from index 1 up to but not including index 3.
  2. Step 2: Identify elements at index 1 and 2

    Elements are 10 (index 1) and 15 (index 2), so output is [10 15].
  3. Final Answer:

    [10 15] -> Option C
  4. Quick Check:

    Slicing arr[1:3] = [10 15] [OK]
Quick Trick: Slice excludes end index, so arr[1:3] gets indices 1 and 2 [OK]
Common Mistakes:
  • Including index 3 element
  • Confusing start index
  • Expecting single element output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes