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

Home » Public Forums » archive » Re: Array comparison part 2
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 part 2 [message #32408 is a reply to message #32398] Thu, 03 October 2002 09:33 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
"Sean Raffuse" <sean@me.wustl.edu> wrote in message
news:anhkqb$ipf$1@newsreader.wustl.edu...
> Thanks for all the help on my first question. I now have a related
> question.
>
> What is the best (read: fastest) way to do the following:
>
> I have an array of coordinates, A = intarr(2,25)
> and I have another array of a specific location, B = [125,1043]
>
> I would like to determine if location B is one of the coordinates in
A. I
> need to know if A[*,?] = 125, 1043
>
> Is it possible to do this without splitting A?

Oh, sure. Using the "replicate data rather than loop" principle, we
stretch B to be the same shape as A, then compare. Try this:

nCoords=25
a=indgen(2,nCoords)
b=[4,5]
print,Total(Total(a EQ (Rebin(b, 2, nCoords)), 1) EQ 2) GT 0

(result is 1, there is a match)

b=[4,6]
print,Total(Total(a EQ (Rebin(b, 2, nCoords)), 1) EQ 2) GT 0

(result is 0, there is no match)

To find *which* one(s) it matches, look at the inner part:
Total(a EQ (Rebin(b, 2, nCoords)), 1) EQ 2

This will be 1 where 'a' matches a pair of 'b' entries, use Where to
find which one (or more) it matches.

Cheers,
--
-Dick

Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL curve fitting program (correction)
Next Topic: Array Subscripting Memory Usage (watch out!)

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

Current Time: Sat Oct 11 21:12:45 PDT 2025

Total time taken to generate the page: 2.24217 seconds