1. Home
  2. Data Science
  3. NumPy
  4. a = np.arange(5); b = a[1:3]; b[0] = 99. What is a now?

Added 2 Nov 2026

a = np.arange(5); b = a[1:3]; b[0] = 99. What is a now?

  1. array([99, 1, 2, 3, 4])
  2. array([0, 99, 99, 3, 4])
  3. array([0, 1, 2, 3, 4])
  4. array([0, 99, 2, 3, 4]) Correct answer

Correct answer

D. array([0, 99, 2, 3, 4])

15 views

MCQSEXAM

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

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More NumPy MCQs

Practise all NumPy MCQs

Similar MCQs