2

I tried np.where but without success:

>>>a = np.array([np.nan, 1])
>>>np.where(a == np.nan)
(array([], dtype=int64),)
Ziofil
  • 1,815
  • 1
  • 20
  • 30

2 Answers2

2

You need to change

np.where(a == np.nan)

to

np.where(np.isnan(a))

NaN values always return false in equality checks, even with another NaN value. So you need to use special functions to check for NaN like np.isnan.

Caleb
  • 284
  • 2
  • 7
1
import numpy as np

x = np.array([0,0,-1,1,np.nan, 0, 1, np.nan])
print np.where(np.isnan(x))

Returns:

(array([4, 7]),)
Robbie
  • 4,672
  • 1
  • 19
  • 24