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 matching elements of array efficiently
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: How to get matching elements of array efficiently [message #69932 is a reply to message #69928] Tue, 23 February 2010 13:06 Go to previous messageGo to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
You might look at Craig Markwardt's program match2 in
http://idlastro.gsfc.nasa.gov/ftp/pro/misc/match2.pro

For your example, one would type
IDL> match2, a, b, suba, subb
IDL> print,where(suba GE 0)
0 2 3 4

You might be able to make match2.pro more efficient, because it also
gives the index of a (not necessarily unique) value in B that matches
a value in A, which is information you don't need. --Wayne


On Feb 23, 3:11 pm, JJ <j...@cornell.edu> wrote:
> Hi All,
>
> I'm looking for an efficient (non-loop) solution to this problem.  I
> have two arrays A, B.  The elements of A are not necessarily unique,
> nor is A necessarily sorted.  I'd like to find all the indices in A
> that match values that occur in B.
>
> For example, if A = [7,1,8,7,8], B = [7,8], the result should be
> [0,2,3,4].
>
> A and B can have many (order millions) of unique values, so I'd rather
> avoid a loop if I can.
>
> Is there any way to do this efficiently?
>
> Thanks.
>
> -JJ
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Intersection of polyline curve and polygon in 3D
Next Topic: Deconvolving a set of points

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

Current Time: Sat Oct 11 00:24:53 PDT 2025

Total time taken to generate the page: 0.48241 seconds