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

Home » Public Forums » archive » Re: Ordered index array
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: Ordered index array [message #45424 is a reply to message #45422] Thu, 08 September 2005 06:02 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paolo Grigis writes:

> But this will fail if 'a' has more elements than the number of
> its different values, for instance a=[3,3,1,2,3,2,2,1,2,3].
>
> One could try this:
>
> PRO test
>
> a=[3,3,1,2,3,2,2,1,2,3]
>
> b=a
> c=intarr(n_elements(a))
>
> h=histogram(a,min=1,reverse_ind=ri)
>
> done=0
> rank=1
> WHILE NOT done DO BEGIN
> actual_value=b[0]
> ind_actual_value=ri[ri[actual_value-1]:ri[actual_value]-1]
> c[ind_actual_value]=rank
> rank=rank+1
> indremove=where(b NE actual_value,count)
> IF count GT 0 THEN b=b[indremove] ELSE done=1
> ENDWHILE
>
> print,a
> print,c
>
> END
>
>
> but it will get inefficient as the numbers of different values
> in 'a' grows, as the code in the loop get called more and more
> times...

Humm. Maybe I'm missing something (I haven't had my coffee yet),
but couldn't this be solved with the original code I wrote by
changing these two lines:

; Create index array and output array.
b = Indgen(N_Elements(a))+ 1
c = Intarr(N_Elements(a))

To these:

; Create index array and output array.
b = Indgen(N_Elements(a) > N_Elements(h)) + 1
c = Intarr(N_Elements(a) > N_Elements(h))

Then,

IDL> a=[3,3,1,2,3,2,2,1,2,3]
IDL> Print, a
1 1 3 4 1 4 4 3 4 1

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[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
Previous Topic: 2 arrays, average, missing data
Next Topic: Re: 2 arrays, average, missing data

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

Current Time: Thu Oct 09 22:50:20 PDT 2025

Total time taken to generate the page: 2.31561 seconds