For a = np.array([3, 8, 1, 9]), what does a[a > 5] return?
-
A
array([3, 1])
-
B
array([8, 9])
Correct answer
-
C
array([1, 3])
-
D
array([False, True, False, True])
Correct answer
B. array([8, 9])
16 views
Explanation
Boolean indexing uses the mask a > 5 to select matching elements. The mask itself is the True/False array, which is a common confusion.
Reference
Asked in: Data Science Interviews, NTS
Doubts & discussion
Not sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ