C.Tals
C.Tals

Reputation: 31

Converntin NaN in a numpy array to large number(i.e. 99999)

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

Answers (1)

Eli Sadoff
Eli Sadoff

Reputation: 7308

You need to use logical indexing to replace all NaNs with 99999. You can do it like this

x[np.isnan(x)] = 99999

This does work in multiple dimensions.

Upvotes: 2

Related Questions