[Numpy-discussion] Initial implementation of histogram_discrete()

Bruce Southey bsouthey@gmail....
Mon Nov 16 09:10:26 CST 2009


On 11/15/2009 01:16 AM, David Warde-Farley wrote:
> 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.
>    
Isn't this indexing invalid if you have a negative value in the original 
array in the first place?
While I have not tried Priit's code (as it is in C), the provided output 
with negative values does not appear to maintain this property. Really 
without changing the output type, I do not see how you can keep this 
indexing property with negative values. So really the comparison has to 
be with histogram().
> 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
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>    
Josef provided the histogram solution using np.arange for the bins that 
appears to be handle negative values except that the indexing is refers 
to position not the value. That is the index is value minus the minimum 
of (zero, min(array)) - which is the indexing as required by Priit's code.


Bruce


More information about the NumPy-Discussion mailing list