[Numpy-discussion] Initial implementation of histogram_discrete()

David Warde-Farley dwf@cs.toronto....
Sun Nov 15 01:16:44 CST 2009


On 14-Nov-09, at 10:57 AM, Bruce Southey wrote:

> Is it just that bincount does not count negative numbers?
> If so, then I would strongly argue that is insufficient for creating
> new function. Rather you need to provide a suitable patch to fix
> bincount or replace bincount with a better version.

The whole point of bincount is that in the result array, the indices  
correspond to _values_ in the original array, i.e. bc = bincount(arr)  
then bc[3] gives me the number of 3's that appear in arr. This is lost  
if bincount starts reporting negatives. I suppose you could return a  
tuple of two arrays, optionally, but I don't know how much use it  
would get.

If you really need to do bincount on an array with negative ints, you  
can just add -arr.min() to the array first and subtract the same value  
when done. Assuming you don't have a huge array this will be very  
fast, and can even be done in place.

David




More information about the NumPy-Discussion mailing list