Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Array Operations
What will be the output of this code?
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr == 3)
A[True False False False]
B[False False True False]
C[False True False False]
D[False False False True]
Step-by-Step Solution
Solution:
  1. Step 1: Compare each element with 3

    Only the third element (index 2) equals 3, so True at that position.
  2. Step 2: Create boolean array

    Result is [False, False, True, False].
  3. Final Answer:

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

    Equality check = boolean array [OK]
Quick Trick: Equality check returns boolean array [OK]
Common Mistakes:
  • Confusing index positions
  • Expecting a single boolean
  • Mixing True and False order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes