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

Home » Public Forums » archive » Re: how to get index of array B data in array A
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: how to get index of array B data in array A [message #14601] Thu, 11 March 1999 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Gary Fu (gfu@seadas.gsfc.nasa.gov) writes:

> Thanks for your quick response. Are there any other methods
> without using the FOR loop?

I don't think so. :-(

Which *almost* guarantees that there will be. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: how to get index of array B data in array A [message #14603 is a reply to message #14601] Thu, 11 March 1999 00:00 Go to previous message
Gary Fu is currently offline  Gary Fu
Messages: 9
Registered: April 1997
Junior Member
David,

Thanks for your quick response. Is there any other methods without
using
the FOR loop, since my A and B array may have more than 250000 elements
?

Thanks.

Gary
>
> Gary Fu (gfu@seadas.gsfc.nasa.gov) writes:
>
>> Is there a simple way to get the index of the array B data in array A ?
>>
>> For example : A = [10,20,30,40,50], B = [10, 20, 33, 10, 30, 40, 9]
>> I want like to get the index array of B in A [0, 1, -1, 0, 2, 3, -1]
>
> I'm afraid you are stuck doing this in a loop because of
> the way the WHERE function compares unequally-sized arrays.
> But you can certainly do something like this:
>
> A = [10,20,30,40,50]
> B = [10, 20, 33, 10, 30, 40, 9]
> C = Indgen(N_Elements(B))
> FOR j=0, N_Elements(B)-1 do C[j] = (Where(A EQ B[j]))[0]
> Print, C
> 0 1 -1 0 2 3 -1
>
> Cheers,
>
> David

*****************************************
* Gary Fu, GSC (301) 286-7107 *
* email : "gfu@seadas.gsfc.nasa.gov" *
* NASA/Goddard Space Flight Center *
*****************************************
Re: how to get index of array B data in array A [message #14608 is a reply to message #14601] Thu, 11 March 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Gary Fu (gfu@seadas.gsfc.nasa.gov) writes:

> Is there a simple way to get the index of the array B data in array A ?
>
> For example : A = [10,20,30,40,50], B = [10, 20, 33, 10, 30, 40, 9]
> I want like to get the index array of B in A [0, 1, -1, 0, 2, 3, -1]

I'm afraid you are stuck doing this in a loop because of
the way the WHERE function compares unequally-sized arrays.
But you can certainly do something like this:

A = [10,20,30,40,50]
B = [10, 20, 33, 10, 30, 40, 9]
C = Indgen(N_Elements(B))
FOR j=0, N_Elements(B)-1 do C[j] = (Where(A EQ B[j]))[0]
Print, C
0 1 -1 0 2 3 -1

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: File pointer problem on PC-IDL
Next Topic: Re: GetColor Program

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

Current Time: Fri Oct 10 16:09:26 PDT 2025

Total time taken to generate the page: 1.67536 seconds