[Numpy-discussion] Long integer 'in' arange()
Rodney Stephenson
rod.stephenson at gmail.com
Thu Jan 15 22:24:29 EST 2009
There was some recent discussion about the (inefficiency) of 'in' when
applied to a large xrange. I was wondering how numpy handled this and
found the following
>>> from numpy import *
>>> u = arange(2**26)
>>> 2**24 in u
True
>>> 2**31 in u
False
>>> 2**32 in u
True
Hmmmm...
>>> u = arange(10, 2**26)
>>> 1 in u
False
>>> 2**37 in u
False
>>> 0 in u
False
>>> u[0]=0
>>> 2**37 in u
True
>>>
So I presume that in casting the long to int for the test is done by
just taking the last 32 bits! Bug or feature? Python silently turns
ints to longs when they overflow, so one should be careful...
More information about the NumPy-Discussion
mailing list