Reputation: 31
I want to replace the NaN in numpy array with a large number such as 99999. I don't want to use numpy.nan_to_num to replace the NaN's with 0 because I want to differentiate between the NaN values and 0 values already in the dataset.
Upvotes: 3
Views: 443
Reputation: 7308
You need to use logical indexing to replace all NaN
s with 99999
. You can do it like this
x[np.isnan(x)] = 99999
This does work in multiple dimensions.
Upvotes: 2