Re: how to get index of array B data in array A [message #14653 is a reply to message #14613] |
Mon, 15 March 1999 00:00  |
Hermann Mannstein
Messages: 22 Registered: September 1995
|
Junior Member |
|
|
Gary Fu wrote:
>
> 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]
If the values in A are confined to a reasonable range, you could do the
following:
a_index = indgen(n_elements(a)) ; the array with the index numbers
c= lonarr(max(a) + 1) - 1 ; some kind of a look-up table,
initialize to -1
c(a) = a_index ; set every value to it's index number
index_a_in_b = c(b < max(a))
With negative numbers in a you will have add the min(a) to both,
A and B
-
Regards,
------------------------------------------------------------ ----
Dr. Hermann Mannstein
/|
DLR-Institut fuer Physik der Atmosphaere / |
Oberpfaffenhofen ,---/--|---,
D-82234 Wessling / / / /
Germany '---|--/---'
| /
tel.: +49-8153-28-2503 |/ DLR
fax.: +49-8153-28-1841 '
mailto:Hermann.Mannstein@dlr.de
http://www.op.dlr.de/ipa/ http://www.op.dlr.de/~pa64
------------------------------------------------------------ ----
|
|
|