我需要找出我的numpy数组中的哪些索引是None。
In [1]: my_array
Out[1]: array([1, 1, 1, None, None, 3, 3, 3], dtype=object)
使用数字执行此类操作非常容易:
In [2]: my_array == 1
Out[2]: array([ True, True, True, False, False, False, False, False], dtype=bool)
但是我坚持用None做同样的事情:
In [3]: my_array == None
/home/opt/anaconda/bin/ipython:1: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
Out[3]: False
每个人都在说避免这种警告的解决方案是使用'is'而不是'==',但它不会返回我所期望的。
In [4]: my_array is None
Out[4]: False
任何想法如何解决问题?