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

Home » Public Forums » archive » Re: using WHERE to search for multiple values
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: using WHERE to search for multiple values [message #30391] Fri, 26 April 2002 09:05
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
Oh boy. It looks to me that the poster in fact wanted to avoid looping
through every element of the array.
Why not try SET_INTERSECTION or what is it called, from David's web
site? The one, real fast, that uses HISTOGRAM?
No loops at all. And you can get either the elements that match or the indices.
Good luck,
Pavel

Doug Martin wrote:
>
> I'm trying to do something like the following:
>
> w=where(im eq val)
>
> with im a byte array (say, 640x480)
> and val an array (say, 10 to 40 long)
>
> I want to find where im is equal to _any_ of the values in val. But,
> val is not always the same size.
>
> Is there a way to do this using one WHERE call? There seems to be a
> giant time difference between:
>
> for i=0,(size(val))[1]-1 do begin
> w=where(im eq val(i))
> ...
> endfor
>
> and
>
> w=where(im eq val(0) or val(1) or val(2) or ...)
>
> (but I can't do the above since val has different sizes from call to
> call)
>
> Sorry for the run-on nature of this post.
>
> Thanks,
> Doug
Re: using WHERE to search for multiple values [message #30394 is a reply to message #30391] Fri, 26 April 2002 08:31 Go to previous message
Jonathan Joseph is currently offline  Jonathan Joseph
Messages: 69
Registered: September 1998
Member
> w=where(im eq val(0) or val(1) or val(2) or ...)

Um, Wouldn't line line have to look more like this to work? :

w = where (im eq val(0) or im eq val(1) or im eq ...)

-Jonathan
Re: using WHERE to search for multiple values [message #30396 is a reply to message #30394] Fri, 26 April 2002 05:15 Go to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Doug Martin wrote:

> I'm trying to do something like the following:
>
> w=where(im eq val)
>
> with im a byte array (say, 640x480)
> and val an array (say, 10 to 40 long)
>
> I want to find where im is equal to _any_ of the values in val. But,
> val is not always the same size.
>
> Is there a way to do this using one WHERE call? There seems to be a
> giant time difference between:
>
> for i=0,(size(val))[1]-1 do begin
> w=where(im eq val(i))
> ...
> endfor
>
> and
>
> w=where(im eq val(0) or val(1) or val(2) or ...)
> (but I can't do the above since val has different sizes from call to
> call)

mask = where(im ne im)
for i=0, count=(size(val))[1]-1 do begin
mask = mask OR (im eq val[i])
endfor
w = where(mask)
Re: using WHERE to search for multiple values [message #30398 is a reply to message #30396] Fri, 26 April 2002 06:08 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Doug Martin wrote:
>
> I'm trying to do something like the following:
>
> w=where(im eq val)
>
> with im a byte array (say, 640x480)
> and val an array (say, 10 to 40 long)
>
> I want to find where im is equal to _any_ of the values in val. But,
> val is not always the same size.
>
> Is there a way to do this using one WHERE call? There seems to be a
> giant time difference between:
>
> for i=0,(size(val))[1]-1 do begin
> w=where(im eq val(i))
> ...
> endfor

why not do it using the loop but using the COMPLEMENT keyword to WHERE so that subsequent
searches don't search the values of IM that you've already matched to the previous VAL(i)? Each
subsequent search will be on a smaller part of the IM array.

Of course:
a) you will have to reconstruct the index values to reflect their IM index rather than their
IM(complement) indices and
b) this may be even slower if the values you're looking for are randomly distributed throughout
the array (i.e. searching an array that is increasingly non-contiguous in memory). You're
arrays aren't that large tho'.

paulv

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
Re: using WHERE to search for multiple values [message #30405 is a reply to message #30396] Thu, 25 April 2002 17:05 Go to previous message
Robert Stockwell is currently offline  Robert Stockwell
Messages: 74
Registered: October 2001
Member
Doug Martin wrote:

> I'm trying to do something like the following:
>
> w=where(im eq val)
>
> with im a byte array (say, 640x480)
> and val an array (say, 10 to 40 long)
>
> I want to find where im is equal to _any_ of the values in val. But,
> val is not always the same size.
>
> Is there a way to do this using one WHERE call? There seems to be a
> giant time difference between:
>
> for i=0,(size(val))[1]-1 do begin
> w=where(im eq val(i))
> ...
> endfor
>
> and
>
> w=where(im eq val(0) or val(1) or val(2) or ...)
>
> (but I can't do the above since val has different sizes from call to
> call)
>
>
> Sorry for the run-on nature of this post.
>
> Thanks,
> Doug
>

Hi Doug,
how about using an execute statement to call the where() a la

for i = 0,n_elements(val) do valstring = valstring + 'or val('+string(i)+')'
r = execute( 'w=where(im eq' + valstring+')')

should be ok unless there are a lot of vals.

cheers
bob

PS YAY, two execute() posts in one day.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Problem with z-buffering using IDLgrPolygon
Next Topic: Re: books about idl

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

Current Time: Wed Oct 08 14:56:31 PDT 2025

Total time taken to generate the page: 0.00472 seconds