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

Home » Public Forums » archive » Re: Array comparison
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: Array comparison [message #32348 is a reply to message #32344] Wed, 02 October 2002 06:19 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Reimar Bauer <R.Bauer@fz-juelich.de> writes:

> Sean Raffuse wrote:
>> Hello,
>>
>> I would like to compare two arrays of different size. What I want to know
>> is if the two arrays share ANY of the same values, regardless of index.
>>
>> e.g.
>>
>> Array1 = [1,2,3,4,5]
>> Array2 = [5,6,7]
>>
>> Comparing these two arrays should return true because they both have the
>> value 5.
>>
>> I know I could do this in a loop, but I need the speed and I'm sure IDL can
>> do this in one line. I'm just not sure how.
[ ... ]
>
> I am using which_indices


Greetings Reimar--

I believe that the original poster wanted was the values, and not the
indices.

Here is what WHICH_INDICES uses:

> FOR i=0L,n_clients DO BEGIN
> a=WHERE(master EQ client[i],count_a)
> IF count_a GT 0 THEN build_vector,result,a
> ENDFOR

I am not sure that the FOR loop with an interior WHERE() will scale to
very large arrays, or very fast calculations, as the original poster
appeared to be requesting.

This actually ties into JD's point from the other day. A loop of
WHERE()'s can be quite slow, even slower than a loop of basic
operations. Its speed here is roughly proportional to N*M, where N
and M are the two input vector sizes. The SORT/UNIQ method is
proportional to (N+M)*ALOG(N+M), which can be a big savings for large
arrays.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Looking for more ideas on code ...
Next Topic: Re: ROI application...

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

Current Time: Wed Oct 08 20:11:13 PDT 2025

Total time taken to generate the page: 0.00472 seconds