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 - Use the mask to select, replace or count those entries. NumPy documents the same rule in its missing-value guidance, which recommends isnan instead of equality. NaN propagates through ordinary arithmetic because the result depends on a value that is unknown.
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
๐ŸŒ
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.
๐ŸŒ
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).
๐ŸŒ
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])
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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),)
๐ŸŒ
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.
๐ŸŒ
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 โ€บ 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.
๐ŸŒ
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.
๐ŸŒ
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....
๐ŸŒ
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
๐ŸŒ
Index.dev
index.dev โ€บ blog โ€บ 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 โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.nan_to_num.html
numpy.nan_to_num โ€” NumPy v2.2 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, ...