1. Home
  2. Data Science
  3. NumPy
  4. What is the output of the following NumPy code snippet?

Added 24 Feb 2024

What is the output of the following NumPy code snippet?

import numpy as np
arr = np.arange(9).reshape(3, 3)
arr_flatten = arr.flatten()
arr_flatten[0] = 99
print(arr)

  1. [[0, 1, 2], [3, 4, 5], [6, 7, 8]] Correct answer
  2. [[99, 1, 2], [3, 4, 5], [6, 7, 8]]
  3. [[0, 99, 2], [3, 4, 5], [6, 7, 8]]
  4. [[0, 1, 2], [3, 4, 5], [6, 7, 99]]

Correct answer

A. [[0, 1, 2], [3, 4, 5], [6, 7, 8]]

14 views

MCQSEXAM

Explanation

The flatten() function returns a copy of the array collapsed into one dimension, modifying it does not affect the original array

Doubts & discussion

Not sure why the answer is A? 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