1. Home
  2. Data Science
  3. NumPy
  4. Why is np.isclose(0.1 + 0.2, 0.3) preferred over (0.1 +…

Added 2 Nov 2026

Why is np.isclose(0.1 + 0.2, 0.3) preferred over (0.1 + 0.2) == 0.3?

  1. It is the only way to compare NumPy arrays
  2. It converts both values into integers first
  3. It allows for tiny floating-point rounding errors Correct answer
  4. It ignores the sign of negative numbers

Correct answer

C. It allows for tiny floating-point rounding errors

14 views

MCQSEXAM

Explanation

0.1 + 0.2 is stored as 0.30000000000000004, so == returns False. np.isclose (and np.allclose for whole arrays) compares within relative and absolute tolerances.

Reference

Asked in: Data Science Interviews

Preparing for an exam?

Doubts & discussion

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