[Numpy-discussion] Initial implementation of histogram_discrete()
plaes at plaes.org
Fri Nov 13 02:41:19 EST 2009
Ühel kenal päeval, N, 2009-11-12 kell 18:16, kirjutas David
> On 12-Nov-09, at 6:09 PM, josef.pktd at gmail.com wrote:
> > On Thu, Nov 12, 2009 at 6:00 PM, Priit Laes <plaes at plaes.org> wrote:
> >> Hey,
> >> I cooked up an initial implementation for one-dimensional
> >> histogram_discrete().
> >> Example:
> >>>> import numpy
> >>>> numpy.histogram_discrete([-1, 9, 9, 0, 3, 5, 3])
> >> array([1, 1, 0, 0, 2, 0, 1, 0, 0, 0, 2])
> >>>> numpy.histogram_discrete([-99999, 99999])
> >> array([1, 0, 0, ..., 0, 0, 1])
> >> Suggestions, criticism? :)
> > Is there a difference to numpy.bincount ?
Yes, it allows negative numbers to be in your list, otherwise it is
almost identical to bincount. (except I stripped the weights option)
> Time to add to this to the FAQ (FWIW I've reinvented the wheel a
> number of times too).
Does anyone have a scenario where one would actually have both negative
and positive numbers (integers) in the list?
Of course, I really didn't know about bincount before I really started
coding histogram_discrete() so maybe it would be nice to have an alias
for it that calls bincount directly, so it would be easier to find?
FAQ entry would be fine too, although I cannot find the FAQ itself from
Numpy homepage. Also I spent some time on IRC (#scipy) complaining about
my woes with histogram(), so please do not be that hard on me for
reinventing a wheel... :P
So, how about numpy.histogram_discrete() that returns data the way
histogram() does: a list containing histogram values (ie counts) and
list of sorted items from min(input)...max(input). ?
More information about the NumPy-Discussion