🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.isnan.html
numpy.isnan — NumPy v2.5 Manual
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. ... Try it in your browser! >>> import numpy as np >>> np.isnan(np.nan) True >>> np.isnan(np.inf) False >>> np.isnan([np.log(-1.),1.,np.log(0)]) array([ ...
🌐
Codecademy
codecademy.com › docs › python › math module › math.isnan()
Python | Math Module | math.isnan() | Codecademy
September 4, 2024 - In Python, the math.isnan() function returns True if the given value is NaN (not a number) and False if the value is a number.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.isnan.html
numpy.isnan — NumPy v2.1 Manual
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. ... >>> import numpy as np >>> np.isnan(np.nan) True >>> np.isnan(np.inf) False >>> np.isnan([np.log(-1.),1.,np.log(0)]) array([ True, False, False])
🌐
W3Schools
w3schools.com › python › ref_math_isnan.asp
Python math.isnan() Method
The math.isnan() method checks whether a value is NaN (Not a Number), or not.
🌐
GeeksforGeeks
geeksforgeeks.org › numpy-isnan-python
numpy.isnan() in Python - GeeksforGeeks
March 8, 2024 - The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array.
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-for-nan-values-in-python
Check For NaN Values in Python - GeeksforGeeks
July 23, 2025 - NaN values are commonly encountered in data science and numerical computing when working with datasets that contain missing, undefined, or invalid values. The numpy.isnan() function is a simple way to check for NaN values in a NumPy array.
Find elsewhere
🌐
Turing
turing.com › kb › nan-values-in-python
How to Check for NaN Values in Python?[With Examples]
import math value = 5.2 if math.isnan(value): print("Value is NaN") else: print("Value is not NaN" ... This method returns True if the value is NaN, and False otherwise. If you're working with arrays or large datasets, the NumPy library provides ...
🌐
Towards Data Science
towardsdatascience.com › home › data science › 5 methods to check for nan values in in python
5 Methods to Check for NaN values in in Python | Towards Data Science
February 23, 2021 - Learn this step by step with the interactive AI and Data Scientist roadmap. isna() in pandas library can be used to check if the value is null/NaN. It will return True if the value is NaN/null.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-isnan-python
numpy.isnan() in Python - GeeksforGeeks
March 8, 2024 - The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.isnan.html
numpy.isnan — NumPy v2.6.dev0 Manual
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. ... Try it in your browser! >>> import numpy as np >>> np.isnan(np.nan) True >>> np.isnan(np.inf) False >>> np.isnan([np.log(-1.),1.,np.log(0)]) array([ ...
🌐
Digis
digiscorp.com › python-check-if-value-is-nan-a-complete-overview
Python Check If Value Is NaN: A Complete Overview
September 7, 2026 - Learn how to check if a value is NaN Python using methods like numpy.isnan, math.isnan, and pandas.isna. Discover the best practices for identifying and handling NaN values efficiently in your Python projects.
🌐
Reddit
reddit.com › r/learnpython › math.isnan()
r/learnpython on Reddit: math.isnan()
December 6, 2013 -

does this EVER return true? gives error on 1/0 and arcsin(2) and '123' and 'abc' and so forth. says it needs a float. but a float is a number, right?

Top answer
1 of 2
4
I think you're confused about what NaN represents. NaN is a special value of a IEEE-754 floating point number that signifies that the result of a floating point computation does not exist (the spec also defines representations for positive and negative infinity). math.isnan will check if a value is this special NaN value, not whether the provided value is of numeric type. In most cases where a NaN would be generated, Python chooses to raise an exception instead of returning NaN (you noticed this is the case for division by zero, but it also applies to taking the square root of a negative number or providing input outside of the domain of inverse trigonometric functions). This behavior differs from some other languages. See also: CPython implementation detail about NaN , Wikipedia article on NaN
2 of 2
3
A float can basically be either a number, positive or negative infinity, or NaN. You can think of NaN and the infinities as special values that a float can have. math.isnan() takes a float and tells you whether its value is NaN. The Python math library is a wrapper around a C library. The corresponding functions in the C library return NaN for many things, but the Python wrapper checks for most (maybe all) of these and raises an exception instead of returning NaN. This is done to make the math module fit in better with the rest of Python, which prefers to raise exceptions instead of returning special values. So, most of the time there's no use for math.isnan() in pure Python code (because Python raises exceptions instead of returning NaN). However, it may be needed in cases where Python code has to process data from external sources (which might produce NaN).
🌐
IncludeHelp
includehelp.com › python › isnotnan-functionality-in-numpy-can-this-be-more-pythonic.aspx
Python - 'isnotnan' functionality in numpy, can this be more pythonic?
October 9, 2023 - # Import numpy import numpy as np # Creating numpy array arr = np.array([np.nan, 1, 2]) # Display original array print("Orignal array:\n",arr,"\n") # Check for each value res = arr[~np.isnan(arr)] # Display result print("Result:\n",res,"\n")
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.isnan.html
numpy.isnan — NumPy v2.2 Manual
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. ... >>> import numpy as np >>> np.isnan(np.nan) True >>> np.isnan(np.inf) False >>> np.isnan([np.log(-1.),1.,np.log(0)]) array([ True, False, False])
🌐
Note.nkmk.me
note.nkmk.me › home › python
What is nan in Python (float('nan'), math.nan, np.nan) | note.nkmk.me
May 9, 2023 - Convert between bool (True/False) and other types in Python · As you can see with bool(), nan is evaluated as True. ... Use math.isnan() or np.isnan(). x = float('nan') if math.isnan(x): print('This is nan.') else: print('This is not nan.') # This is nan.
🌐
Medium
medium.com › @dnaresh2323 › why-nan-nan-is-false-deep-dive-into-pythons-missing-values-dba2bf9452f6
Why NaN == NaN is False? Deep Dive into Python’s Missing Values | by D Naresh | Medium
October 10, 2025 - print(a == b) # False print(a is b) # False print(np.isnan(a)) # True print(np.isnan(b)) # True · NaN (Not a Number) is a special value that represents missing, invalid, or undefined data in Python.