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

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Feb 1 16:55:43 EST 2010


On Mon, Feb 1, 2010 at 12:09 PM, Keith Goodman <kwgoodman at gmail.com> wrote:
> 2010/2/1 Ernest Adrogué <eadrogue at 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 at 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