For a = np.array([10, 20, 30, 40]), what does a[[0, 2]] return?
-
A
array([10, 20, 30])
-
B
array([10, 30])
Correct answer
-
C
array([10, 20])
-
D
array([20, 40])
Correct answer
B. array([10, 30])
15 views
Explanation
Indexing with a list is fancy indexing: it picks elements 0 and 2. Unlike basic slicing, fancy indexing returns a copy, not a view.
Reference
Asked in: Data Science Interviews
Doubts & discussion
Not sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ