MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: BinCounts


Alberto Verga wrote:
> Why does BinCounts[] give lists with unpredictable Dimensions[]?
>
> With[{n = 205}, ll = RandomArray[NormalDistribution[0, 1], {n}];
> Dimensions[BinCounts[ll, {Min[ll], Max[ll], (Max[ll] - Min[ll])/n}]]]
>
>
>
> You may try different values of n (or the same n and different samples of
> the random numbers), and verify that the lenght of the list depends on the
> random realization: somtimes you get n, somtimes n+1.
>

You get different results because of numerical error associated with using 
inexact numbers like machine numbers. Instead, use exact arithmetic or add a 
fudge factor. Assuming you want to get n bins, the following approach will 
always do so for reasonable data:

BinCounts[ll, {Min[ll],Max[ll],(Max[ll]-Min[ll])/n + $MachineEpsilon}]

Alternatively, you could use Rationalize by replacing Min[ll] (and Max[ll]) 
with Rationalize[Min[ll],0] etc.

> Alberto Verga
>
>
>      Alberto Verga
>
>      IRPHE - Université de Provence
>
>      49, rue F. Joliot-Curie, BP 146,
>
>      13384 Marseille, France
>
>
>
>

Carl Woll
Wolfram Research 




  • Prev by Date: Partition(divid string to substring
  • Next by Date: Re: Help with output form?
  • Previous by thread: BinCounts
  • Next by thread: Re: BinCounts