0

I am puzzled by the behaviour of the numpy.where command with None values -- it does not seem to return the correct indices of None and "not None" values:

>>> import numpy as np
>>> a = np.array([None, 1])

#  The following works as expected
>>> a[0]==None
True
>>> a[0]!=None
False
>>> np.where(a)
(array([1]),)

# What's going on here? None of the output seems correct here
>>> np.where(a != None)
(array([0]),)
>>> np.where(a == None)
(array([], dtype=int32),)

Is this intentional or a bug? How can I use numpy.where to find indices equal to None?

I am aware of this question, that talks about using masked arrays to use numpy with arrays with NoneType values, but my question is specifically about numpy.where.

Python: 2.7 Numpy: 1.6.1

Community
  • 1
  • 1
Dhara
  • 6,337
  • 2
  • 30
  • 46

0 Answers0