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([3, 8, 1, 6, 0])
result = arr[arr > 3]
A[8 6]
B[3 8 6]
C[8 1 6]
D[1 0]
Step-by-Step Solution
Solution:
  1. Step 1: Identify elements greater than 3 in arr

    Elements are 8 and 6.
  2. Step 2: Extract these elements using boolean indexing

    arr[arr > 3] returns [8 6].
  3. Final Answer:

    [8 6] -> Option A
  4. Quick Check:

    Elements > 3 = [8 6] [OK]
Quick Trick: Boolean indexing returns elements matching condition [OK]
Common Mistakes:
  • Including elements equal to 3
  • Including elements less than 3
  • Misreading the array values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes