Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8664 > unrolled thread

Binning data points

Started byNiles <niels.martinsen@gmail.com>
First post2012-02-21 11:14 +0000
Last post2012-02-22 10:31 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Binning data points Niles <niels.martinsen@gmail.com> - 2012-02-21 11:14 +0000
    Re: Binning data points Ray Koopman <koopman@sfu.ca> - 2012-02-22 10:31 +0000

#8664 — Binning data points

FromNiles <niels.martinsen@gmail.com>
Date2012-02-21 11:14 +0000
SubjectBinning data points
Message-ID<jhvub4$83n$1@smc.vnet.net>
Hi

Say I have a data set (x_i, y_i) such as of the form

{
{4.4077, 8.41282*10^-7},
{9.39964, 3.3636*10^-6},
{14.3781,  7.56237*10^-6},
{19.3462, 0.00001343},
{24.3073, 0.0000209557},
...
}

The first coordinate is time, the second a weight. The sum of the
weights equal 1, so I am dealing with a probability density function.
I want to bin all the data points such that data points with their x-
coordinates within some range delta_x are binned together, and the
total y-coordinate of that bin should be the sum of all the y's of the
data points in the respective bin. So basically something like a
histogram.

How can I do this?

Best regards.
Niles.

[toc] | [next] | [standalone]


#8695

FromRay Koopman <koopman@sfu.ca>
Date2012-02-22 10:31 +0000
Message-ID<ji2g5f$k94$1@smc.vnet.net>
In reply to#8664
On Feb 21, 3:14 am, Niles <niels.martin...@gmail.com> wrote:
> Hi
>
> Say I have a data set (x_i, y_i) such as of the form
>
> {
> {4.4077, 8.41282*10^-7},
> {9.39964, 3.3636*10^-6},
> {14.3781,  7.56237*10^-6},
> {19.3462, 0.00001343},
> {24.3073, 0.0000209557},
> ...
>
> }
>
> The first coordinate is time, the second a weight. The sum of the
> weights equal 1, so I am dealing with a probability density function.
> I want to bin all the data points such that data points with their x-
> coordinates within some range delta_x are binned together, and the
> total y-coordinate of that bin should be the sum of all the y's of the
> data points in the respective bin. So basically something like a
> histogram.
>
> How can I do this?
>
> Best regards.
> Niles.

data = {{4.4077,  8.41282/10^7},
        {9.39964, 3.3636/10^6},
        {14.3781, 7.56237/10^6},
        {19.3462, 0.00001343},
        {24.3073, 0.0000209557}};

bb = {0,10,20,30,40}; (* bin boundaries *)

(* This gives the count and total probability for each bin. *)
Flatten[Map[If[# == {}, {0,0}, {Length@#,Tr@#[[All,2]]} ]&,
BinLists[data, {bb}, {{-Infinity,Infinity}}], {2}], 1]

{{2, 4.20488*10^-6},
 {2, 0.0000209924},
 {1, 0.0000209557},
 {0, 0}}

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web