numpy' =='切换语义为操作数增长

时间:2018-04-24 17:00:19

标签: python numpy operators equals numpy-broadcasting

偶然发现以下内容:

Python 3.6.0 (default, Jan  9 2017, 22:01:27) 
[GCC 4.8.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> 
>>> np.version.version
'1.14.2'
>>> 
>>> a = np.ones((100,), np.uint8)
>>> (a[:, None] == a).shape
(100, 100)
>>> a = np.ones((10000,), np.uint8)
>>> (a[:, None] == a).shape
(10000, 10000)

到目前为止如此预期,但现在:

>>> a = np.ones((1000000,), np.uint8)
>>> (a[:, None] == a).shape
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'bool' object has no attribute 'shape'

事实上:

>>> a[:, None] == a
False

任何人都可以重现这个吗? 这是一个bug还是某种功能?如果某个功能在某处记录了吗?

其他操作符只会引发内存错误

>>> a[:, None] | a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError

在我看来更有意义。

0 个答案:

没有答案