comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: vector of bin indices using histogram?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: vector of bin indices using histogram? [message #50791 is a reply to message #50789] Wed, 18 October 2006 06:19 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
greg michael wrote:
>
> Can anyone suggest a good way to get a vector of bin indices using
> histogram?
>
> IDL> x=randomu(0,10)
> IDL> print,x
> 0.415999 0.0919649 0.756410 0.529700 0.930436
> 0.383502 0.653919 0.0668422 0.722660 0.671149
>
> I make a histogram anyway:
>
> IDL> h=histogram(x,binsize=.1)
>
> And I also want to know which bin each element went into:
>
> i.e. b=[4,0,7,5,9,3,6,0,7,6]
>
> I could calculate that from the original data of course, but I'm sure
> there must be a trick to get it out of the reverse_indices more
> efficiently (when n_elements is huge).
>

Hi,

I think this does the trick by using the LOCATION output keyword to
HISTOGRAM and then VALUE_LOCATE. I had to specify the MINIMUM bin value
to get the indices lined up to match yours.

x = [ 0.415999, 0.0919649, 0.756410, 0.529700, 0.930436,$
0.383502, 0.653919, 0.0668422, 0.722660, 0.671149]

h = HISTOGRAM(x, BINSIZE = 0.1, LOC = loc, MIN = 0.0)

print, VALUE_LOCATE(loc, x)


Cheers,
Ben


> ---
>
> While experimenting, I came across this, which is not nice...
>
> IDL> x=randomu(0,100)*1000.
> IDL> print,histogram(x,nbins=4)
> 31 34 34 1
>
> The max value sometimes ends up in a bin of its own (usually this last
> bin is zero - I suppose it's a rounding problem).
>
> ---
>
> And then a question about reverse_indices - (I think it's not touched
> in JD's tutorial):
>
> why are the two parts shoved into a single array? Is there an
> application where this arrangement gives some benefit? Wouldn't the
> first half make more sense indexing a second separate vector without
> the need for this offset?
>
>
> regards,
> Greg
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: How to Sort/Uniq a list and keep its original index
Next Topic: Re: fast search

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 08:56:40 PDT 2025

Total time taken to generate the page: 0.48342 seconds