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

Home » Public Forums » archive » The intersection of 2 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: The intersection of 2 arrays [message #8432 is a reply to message #8357] Tue, 04 March 1997 00:00 Go to previous messageGo to previous message
wonko is currently offline  wonko
Messages: 22
Registered: March 1997
Junior Member
williams@irc.chmcc.org (Phil Williams) wrote:

> I know that I can find the union of two arrays by doing something like
>
> temp = [array1, array2]
> union = temp(uniq(temp, sort(temp)))
>
> But how would I go about finding the intersection of the two arrays?
> i.e. Is there a nice vector way of doing it rather than brute force?
> (aka: Which IDL function did I miss this time?)

How big are your elements?

My idea would be something like this:

mask = bytarr( max( [ array1, array2 ] ) + 1 )
mask(array1) = 1b
mask(array2) = mask(array2) + 1b
intersection = where( mask eq 2b, count )

Works for positive values only. And the intersection of [ 1L, 2L ] and [
1L, 100000000L ] might be a problem...


Alex
--
Alex Schuster Wonko@weird.cologne.de
alex@pet.mpin-koeln.mpg.de
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: undefining variables
Next Topic: size of usersym symbols

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

Current Time: Fri Oct 10 14:02:50 PDT 2025

Total time taken to generate the page: 1.51583 seconds