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

Home » Public Forums » archive » Re: Sorting (big) int array: Eliminate for loop
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Sorting (big) int array: Eliminate for loop [message #68047] Tue, 22 September 2009 05:15
Luds is currently offline  Luds
Messages: 7
Registered: September 2009
Junior Member
On Sep 21, 5:37 pm, greg <greg.a...@googlemail.com> wrote:
> How about this...
>
> pro test
>  a=['I','E','F','D','A','J','C','B','G','H']
>  b=['E','B','I','J','D','A','C','H','F','G']
>
>  qa=sort(a)
>  qb=sort(b)
>  qa2=sort(qa)
>  elements=qb[qa2]
>
>  print,b[elements]
> end
>
> IDL> test
> I E F D A J C B G H
>
> Sortingthe sorted indices is the trick. I think it's right, but it
> makes my head hurt anyway.
>
> regards,
> Greg

Perfect, thanks. This works great. Having to do a couple sorts doesn't
add too much overhead to my code. It's much faster now.

By the looks of it the value_locate function could do the trick too,
but it seems to want one of the arrays sorted anyway, which isn't the
case for me.

Thanks for the advice guys. Very helpful.

A
Re: Sorting (big) int array: Eliminate for loop [message #68059 is a reply to message #68047] Mon, 21 September 2009 08:37 Go to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
How about this...

pro test
a=['I','E','F','D','A','J','C','B','G','H']
b=['E','B','I','J','D','A','C','H','F','G']

qa=sort(a)
qb=sort(b)
qa2=sort(qa)
elements=qb[qa2]

print,b[elements]
end

IDL> test
I E F D A J C B G H

Sorting the sorted indices is the trick. I think it's right, but it
makes my head hurt anyway.

regards,
Greg
Re: Sorting (big) int array: Eliminate for loop [message #68060 is a reply to message #68059] Mon, 21 September 2009 08:29 Go to previous message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
I think this is a use for value_locate. But there are lots of
caveats. Like A would have to be sorted which is possibly a speed
hit. Are all the numbers unique? If not then
B[elements]=A could have more than one answer, which could be bad.

Read through the value_locate help and see if it can work for your
application.


Cheers,

Brian

------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: passing parameters to .sav file in IDL VM
Next Topic: Re: HDF: accessing VData in VGroup

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

Current Time: Wed Oct 08 15:12:00 PDT 2025

Total time taken to generate the page: 0.00488 seconds