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

josef.pktd@gmai... josef.pktd@gmai...
Mon Feb 1 15:55:43 CST 2010


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

>>> x=np.arange(5);np.bincount(x[x == 7]).shape
(39672457,)
>>> (np.bincount(x[x == 7])==0).all()
True

>>> x=np.arange(5);np.bincount(x[x == 2]).shape
(3,)

Josef


More information about the NumPy-Discussion mailing list