Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
NumPy - Indexing and Slicing
What is the output of the following code?
import numpy as np
arr = np.array([[5, 10], [15, 20]])
print(arr[0, 1])
A5
B10
C15
D20
Step-by-Step Solution
Solution:
  1. Step 1: Identify the element at arr[0, 1]

    arr[0, 1] means first row, second column. The first row is [5, 10], so second element is 10.
  2. Step 2: Confirm output

    Printing arr[0, 1] outputs 10.
  3. Final Answer:

    10 -> Option B
  4. Quick Check:

    arr[0, 1] = 10 [OK]
Quick Trick: Row 0, column 1 element is arr[0, 1] [OK]
Common Mistakes:
  • Confusing row and column indices
  • Using 1-based indexing
  • Printing the whole row instead of element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes