Python在numpy数组中找不到None

时间:2018-09-15 15:11:12

标签: python numpy

今天,python停止在numpy数组中查找“无”。我的代码由于以下原因而中断。任何线索都很感激。

In [36]: abc = np.array([3,2,None])

In [37]: None is abc[-1]
Out[37]: True

In [38]: None in abc
/Users/py/htrans.py:1: FutureWarning: comparison to `None` will result in an    elementwise object comparison in the future. #!/usr/bin/env python3
Out[38]: False

In [39]: abc==None
/Users/py/htrans.py:1: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future. #!/usr/bin/env python3
Out[39]: False

sys.platform
Out[42]: 'darwin'

sys.version
Out[43]: '3.5.1 |Anaconda 4.0.0 (x86_64)| (default, Dec  7 2015, 11:24:55) \n[GCC 4.2.1 (Apple Inc. build 5577)]'

np.version.version
Out[44]: '1.10.4'

1 个答案:

答案 0 :(得分:2)

链接:https://github.com/numpy/numpy/issues/1608

根据链接,此错误已在Numpy的1.13.0版本中报告并修复。

您可以使用的快速解决方法是:

any(elem is None for elem in abc)