Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
NumPy - Array Operations
What is the output of the following code?
import numpy as np
arr = np.array([3, 7, 2, 9])
result = arr >= 5
print(result)
A[False False False False]
B[True False True False]
C[True True True True]
D[False True False True]
Step-by-Step Solution
Solution:
  1. Step 1: Compare each element with 5

    Elements: 3, 7, 2, 9. Check if each is >= 5: 3>=5 is False, 7>=5 is True, 2>=5 is False, 9>=5 is True.
  2. Step 2: Form boolean array

    The result is [False, True, False, True].
  3. Final Answer:

    [False True False True] -> Option D
  4. Quick Check:

    Element-wise >= 5 = [False True False True] [OK]
Quick Trick: Check each element against 5 carefully [OK]
Common Mistakes:
  • Mixing up >= with >
  • Misreading element values
  • Expecting integer output instead of boolean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes