A[A==NDV]=numpy.nan

A==NDV will produce a boolean array that can be used as an index for A

Answer from Paul on Stack Overflow
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Replace NaN (np.nan) using np.nan_to_num() and np.isnan() | note.nkmk.me
January 23, 2024 - From NumPy version 1.17, the third argument (nan) allows you to specify the value to replace NaN.
🌐
NumPy
numpy.org › doc › stable › user › misc.html
Miscellaneous — NumPy v2.5 Manual
>>> myarr = np.array([1., 0., np.nan, 3.]) >>> np.nonzero(myarr == np.nan) (array([], dtype=int64),)
Discussions

python - Numpy - Replace a number with NaN - Stack Overflow
I am looking to replace a number with NaN in numpy and am looking for a function like numpy.nan_to_num, except in reverse. The number is likely to change as different arrays are processed because e... More on stackoverflow.com
🌐 stackoverflow.com
python - How to check for NaN values - Stack Overflow
The series I'm checking is strings with missing values are 'nans' (???) so this solution works where others failed. 2018-11-03T22:49:08.047Z+00:00 ... numpy.nan is a regular Python float object, just like the kind returned by float('nan'). Most NaNs you encounter in NumPy will not be the numpy.nan ... More on stackoverflow.com
🌐 stackoverflow.com
Pandas help, cannot convert float64 value to NaN?
Try this: df.loc[pd.isna(df['A']), 'B'] = np.nan # if col A is None or np.nan then set col B to np.nan df.loc[pd.isnull(df['A']), 'B'] = np.nan # if col A is None or np.nan then set col B to np.nan Basically use pd.isna() instead of your Boolean statement. You can’t use Boolean statements to compare None/Null values in Python More on reddit.com
🌐 r/learnpython
4
5
March 6, 2024
cannot convert float NaN to integer
Can you post a code snippet? More on reddit.com
🌐 r/learnpython
6
1
February 23, 2023
People also ask

Should I use np.isnan or pandas isna?
Use np.isnan for numeric NumPy values. Use pandas isna or a Series or DataFrame isna method when the data may contain pandas missing markers, None or NaT.
🌐
askpython.com
askpython.com › python › examples › nan-in-numpy-and-pandas
Understanding np.nan in NumPy and Pandas - AskPython
Is np.nan a float?
Yes. np.nan is a floating-point value, so including it in a NumPy array of integers causes the array to use a floating-point dtype.
🌐
askpython.com
askpython.com › python › examples › nan-in-numpy-and-pandas
Understanding np.nan in NumPy and Pandas - AskPython
What does np.nan do?
np.nan is a floating-point NaN value used to mark an unavailable numeric entry. Use np.isnan to detect it in a NumPy array.
🌐
askpython.com
askpython.com › python › examples › nan-in-numpy-and-pandas
Understanding np.nan in NumPy and Pandas - AskPython
🌐
AskPython
askpython.com › python › examples › nan-in-numpy-and-pandas
Understanding np.nan in NumPy and Pandas - AskPython
September 30, 2026 - Keep the environment active while running the Python examples. The commands use the package releases installed when you create it. NumPy promotes this array to float64 because np.nan is a floating-point value and the other entries are integers.
🌐
Reintech
reintech.io › blog › handling-missing-data-nan-values-numpy
Handling Missing Data and NaN Values in NumPy - Reintech
June 13, 2026 - NumPy uses IEEE 754 floating-point special value np.nan to represent missing or undefined numerical data. Unlike None in Python, NaN is a float type that propagates through calculations—any operation involving NaN typically returns NaN.
🌐
DataCamp
datacamp.com › home › tutorials › python › python nan: 4 ways to check for missing values in python
Python NaN: 4 Ways to Check for Missing Values in Python | DataCamp
February 15, 2024 - This article aims to equip you ... the approach largely depends on the data structure you're working with. NumPy's isnan() function is ideal for identifying NaNs in numeric arrays or single values, offering a straightforward and efficient solution....
Find elsewhere
🌐
EDUCBA
educba.com › home › software development › software development tutorials › numpy tutorial › numpy nan
NumPy NaN | Working of NumPy NaN in Python with Examples
April 19, 2023 - In Python, NumPy NAN stands for not a number and is defined as a substitute for declaring value which are numerical values that are missing values in an array as NumPy is used to deal with arrays in Python and this can be initialized using numpy.nan ...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Appdividend
appdividend.com › np-nan
Numpy.nan (np.nan) in Python
July 11, 2025 - The important thing I would like you to take away from this is that all our integers have been converted to floats because NumPy has defined the NaN data type as a floating-point number. You can use the double equal (==) operator to compare two NaN values.
🌐
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 - In addition, nan is defined in math (standard library) and NumPy; both NaN and NAN are defined as aliases in NumPy. math.nan — Mathematical functions — Python 3.11.3 documentation ...
🌐
Python Guides
pythonguides.com › python-numpy-nan
How NumPy Create NaN Array in Python?
May 16, 2025 - Read ValueError: setting an array element with a sequence error in Python · One of the simplest ways to create a NaN array is by using the np.full() function combined with NumPy’s built-in np.nan constant in Python.
🌐
Plain English
python.plainenglish.io › handling-missing-data-and-nan-values-in-numpy-fa6421182c80
Handling Missing Data and NaN Values in NumPy | by NIBEDITA (NS) | Python in Plain English
August 23, 2026 - Missing values can break Statistical Calculations. They can distort ML Models if not handled carefully. A proper approach depends on Business Context and Data Size. ... Removing NaNs if the missing data is tiny. Replacing NaNs using Mean/Median/Mode or other Techniques. Missing data is inevitable in real-world datasets. I know I’m using some fancy words.😂 But okay! With NumPy’s methods like “isnan()”, “nanmean()”, and Boolean masking, we can handle them efficiently and confidently.
🌐
Interactive Chaos
interactivechaos.com › en › python › function › numpynan
numpy.nan | Interactive Chaos
January 16, 2021 - numpy.nan is a special value from the NumPy library that represents the null value · numpy.nan does not accept arguments
🌐
Index.dev
index.dev › blog › check-for-nan-values-in-python
4 Easy Ways to Check for NaN Values in Python (+Examples)
In Python, NaN can be represented using different methods: Using the built-in float function: nan_value = float('nan') Using NumPy: import numpy as np nan_value = np.nan
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.5 Manual
If x is inexact, NaN is replaced by zero or by the user defined value in nan keyword, infinity is replaced by the largest finite floating point values representable by x.dtype or by the user defined value in posinf keyword and -infinity is replaced by the most negative finite floating point values representable by x.dtype or by the user defined value in neginf keyword.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.1 Manual
If x is inexact, NaN is replaced by zero or by the user defined value in nan keyword, infinity is replaced by the largest finite floating point values representable by x.dtype or by the user defined value in posinf keyword and -infinity is replaced by the most negative finite floating point ...
🌐
NumPy
numpy.org › doc › stable › reference › constants.html
Constants — NumPy v2.5 Manual
>>> import numpy as np >>> np.nan nan >>> np.log(-1) np.float64(nan) >>> np.log([-1, 1, 2]) array([ nan, 0.
🌐
Turing
turing.com › kb › nan-values-in-python
How to Check for NaN Values in Python?[With Examples]
If you're working with arrays or large datasets, the NumPy library provides a convenient function called isnan() to check for NaN in Python values. This method works efficiently with both scalar values and arrays.
🌐
Stack Abuse
stackabuse.com › bytes › how-to-check-for-nan-values-in-python
How to Check for NaN Values in Python
September 22, 2023 - In this example, we have an array with two NaN values. When we use numpy.isnan(), it returns a Boolean array where True corresponds to the positions of NaN values in the original array.