[Numpy-discussion] histogram: sum up values in each bin

josef.pktd@gmai... josef.pktd@gmai...
Thu Aug 27 12:27:29 CDT 2009


On Thu, Aug 27, 2009 at 12:49 PM, Tim
Michelsen<timmichelsen@gmx-topmail.de> wrote:
>> Tim, do you mean, that you want to apply other functions, e.g. mean or
>> variance, to the original values but calculated per bin?
> Sorry that I forgot to add this. Shame.
>
> I would like to apply these mathematical functions on the original values
> stacked in the respective bins.
>
> For instance:
>
> The sample data measures the wight of an animal.
>
> 1) historam give a count of how many values are in each bin.
>
> I would like to calculate the average wight of all animals
> sorted in bin1, bin2 etc.
>
> This is also useful in where you have a time component.
>
> In Spreadsheets I would use a '=' to reference to the original data and then
> either sum it up or count it per class.
>
> I hope this is somehow understandable.

Yes, it is a quite common use case for descriptive statistics, and I'm
starting to collect different ways of doing it.

In your case, Vincents way is the easiest.

If you need to be faster, or you want to apply the same classification
also to other variables, e.g. size of the animal,.., then creating a
label array would be a more flexible solution.

There was a similar thread recently on the scipy-user list for sorted
arrays: "How to average different pieces or an array?"

Josef

>
> Thanks,
> Timmie


More information about the NumPy-Discussion mailing list