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 #45444 is a reply to message #45443] Wed, 07 September 2005 10:01 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Emmanuel Christophe writes:

> I would like to change the values on an array according to the order
> they appear. Following this example:
>
> starting with the array
> [3,6,2,1,2,8,1,1]
> I would like to get
> [1,2,3,4,3,5,4,4]
>
> 3 being the first value seen it is affected to 1
> 6 being the second, affected to 2
> ...
>
> I guess this process is similar to lookup tables, or color tables. As I
> would like to process quite big arrays (>60000 long elements), i'm
> looking for an efficient function. I don't really know what to look for
> in IDL help to find something which could help.

How about this:

PRO TEST
a = [3,6,2,1,2,7,1,1]
h = Histogram(a, Reverse_Indices=ri, Min=0)
b = Indgen(N_Elements(h)) + 1
c = Intarr(N_Elements(h))
FOR j=0,N_Elements(h)-1 DO BEGIN
IF ri[j+1] NE ri[j] THEN $
c[ri[ri[j]:ri[j+1]-1]] = Min(b[ri[ri[j]:ri[j+1]-1]])
ENDFOR
Print, c
END

1 2 3 4 3 6 4 4

Note that your original example is wrong. :-)

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:55:57 PDT 2025

Total time taken to generate the page: 1.03857 seconds