Bird
0
0

What does the numpy expression arr == 5 return when arr is a numpy array?

easy📝 Conceptual Q11 of 15
NumPy - Array Operations
What does the numpy expression arr == 5 return when arr is a numpy array?
AThe sum of all elements equal to 5
BAn array of True/False values showing where elements equal 5
CThe count of elements equal to 5
DA single True or False value
Step-by-Step Solution
Solution:
  1. Step 1: Understand element-wise comparison

    The expression arr == 5 compares each element of the array to 5 individually.
  2. Step 2: Result type of comparison

    This returns a new array of the same shape with True where the element equals 5, and False otherwise.
  3. Final Answer:

    An array of True/False values showing where elements equal 5 -> Option B
  4. Quick Check:

    Element-wise comparison = Boolean array [OK]
Quick Trick: Remember == returns True/False array element-wise [OK]
Common Mistakes:
  • Thinking it returns a count or sum
  • Expecting a single True/False value
  • Confusing == with assignment =

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes