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 OverflowAskPython
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.
Fast check for NaN in NumPy
03:07
Handling Missing Values with Numpy - YouTube
01:17
Python NumPy For Your Grandma - 3.5 nan - YouTube
10:16
NaN vs. NA — understanding Pandas nullable types - YouTube
02:09
How do I remove NaN values from a NumPy array? - YouTube
06:33
4 np.nan and np.inf - Numpy Crash Course for Data Science | Numpy ...
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.
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.
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])
Top answer 1 of 2
82
A[A==NDV]=numpy.nan
A==NDV will produce a boolean array that can be used as an index for A
2 of 2
7
You can also use np.where to replace a number with NaN.
arr = np.where(arr==NDV, np.nan, arr)
For example, the following result can be obtained via
arr = np.array([[1, 1, 2], [2, 0, 1]])
arr = np.where(arr==1, np.nan, arr)

This creates a new copy (unlike A[A==NDV]=np.nan) but in some cases that could be useful. For example, if the array was initially an int dtype, it will have to converted into a float array anyway (because replacing values with NaN won't work otherwise) and np.where can handle that.
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.
Call: +917738666252
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, ...
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...