Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q5 of 15
NumPy - Indexing and Slicing
What will be the output of the following code?
import numpy as np
arr = np.arange(16).reshape(4,4)
print(arr[2:, 1:3])
A[[ 6 7] [10 11]]
B[[ 9 10] [13 14]]
C[[10 11] [14 15]]
D[[ 8 9] [12 13]]
Step-by-Step Solution
Solution:
  1. Step 1: Create the array and reshape

    Array is 4x4 with values 0 to 15 arranged row-wise.
  2. Step 2: Slice rows from index 2 to end and columns 1 to 3 (exclusive)

    Rows 2 and 3: [8,9,10,11] and [12,13,14,15]. Columns 1 and 2: indices 1 and 2.
  3. Final Answer:

    [[ 9 10] [13 14]] -> Option B
  4. Quick Check:

    Rows 2+, columns 1-2 = [[9 10], [13 14]] [OK]
Quick Trick: Remember stop index is exclusive in slicing [OK]
Common Mistakes:
  • Including wrong columns
  • Using wrong row indices
  • Misreading reshape output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes