[Numpy-discussion] np.bincount raises MemoryError when given an empty array

David Cournapeau david@silveregg.co...
Mon Feb 1 19:37:54 CST 2010


josef.pktd@gmail.com wrote:
> On Mon, Feb 1, 2010 at 12:09 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
>> 2010/2/1 Ernest Adrogué <eadrogue@gmx.net>:
>>> Hello,
>>>
>>> Consider the following code:
>>>
>>> for j in range(5):
>>>        f = np.bincount(x[y == j])
>>>
>>> It fails with MemoryError whenever y == j is all False element-wise.
>>>
>>>
>>> In [96]: np.bincount([])
>>> ---------------------------------------------------------------------------
>>> MemoryError                               Traceback (most recent call last)
>>>
>>> /home/ernest/<ipython console> in <module>()
>>>
>>> MemoryError:
>>>
>>> In [97]: np.__version__
>>> Out[97]: '1.3.0'
>>>
>>> Is this a bug?
>>>
>>> Bye.
>> I get it to work sometimes:
>>
>> $ ipython
>>>> import numpy as np
>>>> np.bincount([])
>> ---------------------------------------------------------------------------
>> MemoryError:
>>>> np.bincount(())
>>   array([0])
>>>> np.bincount([])
>>   array([0])
>>>> np.bincount([])
>> ---------------------------------------------------------------------------
>> MemoryError:
>>>> np.__version__
>>   '1.4.0rc2'
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
> 
> I don't get a memory error but the results are strange for empty

That may just be because you have enough memory for the (bogus) result: 
the value is a random memory value interpreted as an intp value, hence 
most likely very big on 64 bits system.

It should be easy to fix, but I am not sure what is the expected result. 
An empty array ?

David


More information about the NumPy-Discussion mailing list