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

Home » Public Forums » archive » Re: Finding Common Elements in Two Arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Finding Common Elements in Two Arrays [message #2106 is a reply to message #2104] Thu, 02 June 1994 07:17 Go to previous messageGo to previous message
zawodny is currently offline  zawodny
Messages: 121
Registered: August 1992
Senior Member
In article <1JUN199416454238@stars.gsfc.nasa.gov>, kucera@stars.gsfc.nasa.gov (Terry Kucera) writes:
> I'm looking for a quick way to compare two arrays in IDL, A and B,
> and determine which elements of B are also in A,
> so if:
> A=[2,1,3,5,3,8,2,5]
> B=[3,4,2,8,7,8]
> I would get [0,2,3,5], because 3, 2, and 8 are in A as well as B.
>
> I can do this with loops, but that takes too long for big arrays. Does anyone
> have a way to do this using array functions or perhaps an external routine?
> Terry Kucera
> kucera@stars.gsfc.nasa.gov

If you are dealing strictly with integers, I'd use histogram on both
vectors, multiply them together and then use where to find non-zero values.

Hist_a = histogram(a,max=maximum_expected_value)
Hist_b = histogram(b,max=maximum_expected_value)
Inter = where(Hist_a*Hist_b)

and Inter should then contain the array you seek.

--
Joseph M. Zawodny (KO4LW) NASA Langley Research Center
Internet: zawodny@arbd0.larc.nasa.gov MS-475, Hampton VA, 23681-0001
Packet: ko4lw@n4hog.va.usa
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: IDL hangs with Bessel Function
Next Topic: Modular programming in IDL....trouble

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

Current Time: Sun Oct 12 00:46:45 PDT 2025

Total time taken to generate the page: 1.04003 seconds