7

Just stumbled over the following:

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)

So far so expected, but now:

>>> 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'

In fact:

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

Can anyone reproduce this? Is it a bug or some kind of feature? If a feature is it documented somewhere?

Other operators just raise a memory error

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

which makes much more sense in my opinion.

Paul Panzer
  • 51,835
  • 3
  • 54
  • 99
  • How long does `a[:, None] == a` take to compute in the last scenario? On my system, running this crashed my interpreter. (version '1.14.0' btw, so this is likely a bug) – cs95 Apr 24 '18 at 17:06
  • @cᴏʟᴅsᴘᴇᴇᴅ It returns instantly. Ok, timed it: around 10 us – Paul Panzer Apr 24 '18 at 17:08
  • Definitely a bug, cannot reproduce on 1.14.0. You should file a bug report... – cs95 Apr 24 '18 at 17:09
  • 2
    I can reproduce it with the very same setup, the comparison returns `False` instantly. `np.equal` raises `MemoryError`. This answer may be related: https://stackoverflow.com/a/35397876/5629339 – filippo Apr 24 '18 at 17:12
  • 1
    @filippo Geez, googling is really not my strongest suit. Thanks, that's very likely it. – Paul Panzer Apr 24 '18 at 17:17
  • 1
    From the link by @filippo it seems like this is known behavior that's deprecated since 1.9, but still hasn't actually been removed yet by 1.14? So presumably the answer is to not depend on either behavior until some point even farther in the future… It's obviously not that easy to do that without knowing in advance what might cause a `MemoryError`, except by `np.equal` whenever there's any chance at all of one? – abarnert Apr 24 '18 at 17:18

0 Answers0