What does (scores >= 50).sum() return for a NumPy array of exam scores?
-
A
The total of all scores at or above 50
-
B
The average of every score in the array
-
C
The number of scores that are at least 50
Correct answer
-
D
The index of the first score above 50
Correct answer
C. The number of scores that are at least 50
16 views
Explanation
Comparison produces a boolean array, and summing treats True as 1. This is a fast, vectorised way to count elements that meet a condition.
Reference
Asked in: Data Science Interviews
Doubts & discussion
Not sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ