Why is np.isclose(0.1 + 0.2, 0.3) preferred over (0.1 + 0.2) == 0.3?
A
It is the only way to compare NumPy arrays
B
It converts both values into integers first
C
It allows for tiny floating-point rounding errors
Correct answer
D
It ignores the sign of negative numbers
Correct answer
C. It allows for tiny floating-point rounding errors
14 views
⚔️
Challenge a friend on NumPy
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
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
Doubts & discussionNot sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ a = np.arange(5); b = a[1:3]; b[0] = 99. What is a now? Next MCQ › For 2-D NumPy arrays A and B, what does A @ B compute?