Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
NumPy - Array Data Types
What is the output of this code?
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
mask = arr > 3
print(mask)
A[3 4 5]
B[True True True False False]
C[False False False True True]
D[1 1 1 0 0]
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition arr > 3

    For each element in arr, check if it is greater than 3: 1>3 False, 2>3 False, 3>3 False, 4>3 True, 5>3 True.
  2. Step 2: Understand the mask output

    The mask is a boolean array showing True where condition is met, False otherwise: [False False False True True].
  3. Final Answer:

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

    Condition mask = [False False False True True] [OK]
Quick Trick: Compare array with condition to get boolean mask [OK]
Common Mistakes:
  • Confusing boolean mask with integer 1/0
  • Expecting filtered values instead of mask
  • Mixing up True and False positions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes