# Re: how to get index of array B data in array A

• Subject: Re: how to get index of array B data in array A
• From: davidf(at)dfanning.com (David Fanning)
• Date: Thu, 11 Mar 1999 09:58:40 -0700
• Newsgroups: comp.lang.idl-pvwave
• Organization: Fanning Software Consulting
• Xref: news.doit.wisc.edu comp.lang.idl-pvwave:13918

```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

```