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
🌐
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.
People also ask

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
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
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
🌐
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
🌐
Appdividend
appdividend.com › np-nan
Numpy.nan (np.nan) in Python
July 11, 2025 - The np.nan is a special floating-point constant defined in the NumPy library that represents "Not a Number" (NaN).
🌐
Interactive Chaos
interactivechaos.com › en › python › function › numpynan
numpy.nan | Interactive Chaos
January 16, 2021 - Python scenarios · Full name · numpy.nan · Library · NumPy · Syntax · numpy.nan · Description · numpy.nan is a special value from the NumPy library that represents the null value. Parameters · numpy.nan does not accept arguments. Result · numpy.nan returns a value of type float.
🌐
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.
🌐
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.
Find elsewhere
🌐
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.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.isnan.html
numpy.isnan — NumPy v2.1 Manual
>>> 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])
🌐
NumPy
numpy.org › doc › stable › user › misc.html
Miscellaneous — NumPy v2.5 Manual
>>> np.nan == np.nan # is always False! Use special numpy functions instead.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.1 Manual
Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-for-nan-values-in-python
Check For NaN Values in Python - GeeksforGeeks
July 23, 2025 - In Python, NaN stands for "Not a Number". It is a special floating-point value defined in the IEEE 754 floating-point standard, used to represent undefined or unrepresentable numerical results.
🌐
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
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.5 Manual
Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Functions ignoring NaN (np.nansum, np.nanmean, etc.) | note.nkmk.me
January 23, 2024 - In NumPy, functions like np.sum() and np.mean() return NaN if the array (ndarray) contains any NaN values. To perform calculations that ignore NaN, use functions such as np.nansum() and np.nanmean(). ... For basics on handling NaN in Python, ...
🌐
CASRAI
casrai.org › guides › research tools & software › statistical software for research › numpy nan: how to detect, ignore and replace np.nan
NumPy NaN: Detect, Ignore and Replace np.nan — CASRAI
2 weeks ago - The NumPy manual defines np.nan as the “IEEE 754 floating point representation of Not a Number (NaN)”, and notes that NumPy follows the IEEE Standard for Binary Floating-Point for Arithmetic, so NaN is not equivalent to infinity.
🌐
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 - Handling Missing Data and NaN Values in NumPy Hey guys! Welcome back to our NumPy for Data Science series. This is going to be the 6th article of this series. In our previous article, we discussed …
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-nan_to_num-in-python
numpy.nan_to_num() in Python - GeeksforGeeks
July 10, 2025 - DSA Python · Data Science · NumPy ... · numpy.nan_to_num() function replaces NaN (Not a Number) with a specified numerical value (default is 0), and optionally converts positive or negative infinity to finite numbers...