a = np.arange(5); b = a[1:3]; b[0] = 99. What is a now?
-
A
array([99, 1, 2, 3, 4])
-
B
array([0, 99, 99, 3, 4])
-
C
array([0, 1, 2, 3, 4])
-
D
array([0, 99, 2, 3, 4])
Correct answer
Correct answer
D. array([0, 99, 2, 3, 4])
15 views
Explanation
Basic slicing returns a view that shares memory with the original, so changing b changes a. Use .copy() when an independent array is needed.
Reference
Asked in: Data Science Interviews
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ