Reputation: 11
brands
is a numpy array with 2314 elements. I am checking if there is a nan value in the array. The output shows false but when I tried intersection function with np.nan
, it shows the common element as nan. So how come I cant find the nan value in array? And how do I remove it?
Upvotes: 1
Views: 1434
Reputation: 29982
NaN is not equal with itself.
>>> np.nan != np.nan
True
You can use numpy.isnan
to check
np.isnan(brands)
To remove nan
, you can use
brands = brands[~np.isnan(brands)]
Upvotes: 3
Reputation: 394
The issue is that numpy's nan cannot be compared to itself, or in other words numpy.nan == numpy.nan
returns False. Use instead numpy.isnan()
.
Upvotes: 4