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

Home » Public Forums » archive » 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
Interesting property of sort [message #53994] Wed, 16 May 2007 05:41 Go to previous message
cmancone is currently offline  cmancone
Messages: 30
Registered: May 2007
Member
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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: why I can't use the max memory available?
Next Topic: embedded formatting hell: x-bar meaning "mean of x"

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

Current Time: Fri Oct 10 00:44:18 PDT 2025

Total time taken to generate the page: 0.64459 seconds