On Feb 22, 1:54=A0am, "Kenneth P. Bowman" <k-bow...@[EMAIL PROTECTED]
> wrote:
>
>
> times slower than usingHISTOGRAMwith regular bins due to the time
> required to do a binary search.
>
> ;UseHISTOGRAMto bin 10^7 numbers with evenly-spaced bins
>
> r =A0=3D 100.0*RANDOMU(seed, 10^7)
> t0 =3D SYSTIME(/SECONDS)
> h1 =3DHISTOGRAM(r, MIN =3D 0.0, BINSIZE =3D 1.0)
> PRINT, 'Time for evenly-spaced bins =A0 : ', SYSTIME(/SECONDS) - t0
>
> ;Use VALUE_LOCATE andHISTOGRAMto bin 10^7 numbers
> ;with unevenly-spaced bins
>
> bins =3D [0.0, FINDGEN(99) + 0.1*RANDOMU(seed, 99)]
> t0 =A0 =3D SYSTIME(/SECONDS)
> i =A0 =A0=3D VALUE_LOCATE(bins, r)
> h2 =A0 =3DHISTOGRAM(i, MIN =3D 0, BINSIZE =3D 1)
> PRINT, 'Time for unevenly-spaced bins : ', SYSTIME(/SECONDS) - t0
My first comp.lang.idl post ..
I think you may have to add nbins to the above histogram call as if
none of the elements lie in your desired bin range (i.e. value_locate
returns an array of -1's) histogram will not return a mapping into
your desired bin range.
e.g
function hist_ireg_bin, data, bin
; Calculate a histogram with irregular bin spacing
tmp =3D VALUE_LOCATE(bin, data)
return, HISTOGRAM(tmp, MIN =3D 0, BINSIZE =3D 1, nbins =3D
n_elements(bin))
end


|