Where A
is your 2D array:
import numpy as np
A[np.isnan(A)] = 0
The function isnan
produces a bool array indicating where the NaN
values are. A boolean array can by used to index an array of the same shape. Think of it like a mask.
More Related Contents:
- What is the difference between size and count in pandas?
- What is the difference between NaN and None?
- Removing nan values from an array
- Why in numpy `nan == nan` is False while nan in [nan] is True?
- Numpy integer nan [duplicate]
- Interpolate NaN values in a numpy array
- How do I remove NaN values from a NumPy array?
- Comparing numpy arrays containing NaN
- NumPy: calculate averages with NaNs removed
- NaNs as key in dictionaries
- Numpy – Replace a number with NaN
- Python’s and Numpy’s nan and set
- What are some possible calculations with numpy or scipy that can return a NaN? [closed]
- Numpy array assignment with copy
- Repeating each element of a numpy array 5 times
- Calculate weighted average using a pandas/dataframe
- Comparing previous row values in Pandas DataFrame
- Ambiguity in Pandas Dataframe / Numpy Array “axis” definition
- How to create a numpy array of arbitrary length strings?
- Subsetting a 2D numpy array
- Counting unique values in a column in pandas dataframe like in Qlik?
- fitting exponential decay with no initial guessing
- How to plot line (polygonal chain) with numpy/scipy/matplotlib with minimal smoothing
- How to make numpy.argmax return all occurrences of the maximum?
- read matlab v7.3 file into python list of numpy arrays via h5py
- module ‘pandas’ has no attribute ‘read_csv
- Weighted random sample without replacement in python
- Converting 2D Numpy array of grayscale values to a PIL image
- Convert a column of timestamps into periods in pandas
- Generate random array of floats between a range