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 #8418 is a reply to message #8357] Thu, 06 March 1997 00:00 Go to previous messageGo to previous message
James Tappin is currently offline  James Tappin
Messages: 54
Registered: December 1995
Member
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?)

Whether it's feasible depends on the size of the arrays. As far as I know
there is no really nice way to do it. But for smallish 1-D arrays I think
the following will work

temp = reform(array2,1,n_elements(array2))
imatch = array1(*,intarr(n_elements(array2)) eq $
temp(intarr(n_elements(array1),*)
sum=total(imatch,1)
locs=where(sum ne 0)
inter = array1(locs)

Several of those lines can probably be condensed together, but even so I'd
rather not try it for two 13000 element arrays.

+------------------------+---------------------------------- --+---------+
| James Tappin, | School of Physics & Space Research | O__ |
| sjt@star.sr.bham.ac.uk | University of Birmingham | -- \/` |
| Ph: 0121-414-6462. Fax: 0121-414-3722 | |
+----------------------------------------------------------- --+---------+
[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:04:55 PDT 2025

Total time taken to generate the page: 0.56110 seconds