1. Home
  2. Data Science
  3. NumPy
  4. What is the output of np.nanmean([1, np.nan, 3])?

Added 24 Feb 2024

What is the output of np.nanmean([1, np.nan, 3])?

  1. nan
  2. 2.0 Correct answer
  3. 1.5
  4. 3.0

Correct answer

B. 2.0

12 views

MCQSEXAM

Explanation

The result is 2.0. np.nanmean() ignores NaN values and averages the rest: (1 + 3) / 2 = 2.0.

Ordinary np.mean() on the same data would return nan, because any arithmetic involving NaN produces NaN.

Keep preparing with more Data Science MCQs on MCQsExam.com.

Doubts & discussion

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