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

Home » Public Forums » archive » Re: Interesting property of sort
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: Interesting property of sort [message #53991 is a reply to message #53990] Wed, 16 May 2007 06:35 Go to previous messageGo to previous message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On May 16, 7:41 am, cmanc...@ufl.edu wrote:
> while attempting to build a faster star matching algorithm, I
> "discovered" an interesting property of sort - or, an interesting use
> for it. Of course, you guys have all probably seen this before
> anyway, but I thought I would share it because it can be very useful.
> Essentially, I found the easy way to make a sort lookup table. So,
> let's say you have the array:
>
> test = [5,4,1,3,2]
>
> and you sort it:
>
> sortindex = sort(test)
> sorted = test[sortindex]
>
> now, what if you want to know where the 5 (or any other number) ended
> up in the sorted array? It turns out that you can make a lookup table
> by simply sorting sortindex.
>
> lookup = sort(sortindex)
>
> so, if you wanted to know where the first element of test ended up in
> the sorted list, you would say:
>
> print,lookup[0]
> ; prints "4"
> print,sorted[lookup[0]]
> ; prints "5"
>
> In retrospect, I suppose this result isn't suprising, and probably
> should have been immediately obvious. Still, I thought I'd share.

To add the obvious(?) - be careful if you try this with repeated
values.

test = [5,4,4,1,3,2]
sortindex = sort(test)
lookup = sort(sortindex)
print, lookup[4]
; prints "2" [hey what about "1"]...
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Thicker points
Next Topic: Re: how to write a K with a hat symbol above

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

Current Time: Sat Oct 18 13:50:52 PDT 2025

Total time taken to generate the page: 0.78272 seconds