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

Home » Public Forums » archive » Re: quick search of array
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: quick search of array [message #44569] Thu, 23 June 2005 13:21
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
<tanqian@hotmail.com> wrote in message
news:1119544592.305102.257100@g49g2000cwa.googlegroups.com.. .
> Hi,
>
> I have four arraies
>
> all_time = fltarr(10000)
> all_location = fltarr(3, 10000)
>
> sel_time = fltarr(4000)
> sel_location = fltarr(3,4000)
>
> the 'sel_time' is a subset of 'all_time'. Is there a quick way I could
> find index 'j' of all_time for each sel_time(i) (when
> abs(all_time(j)-sel_time(i)) lt 1e-5)? So I could use that index to
> pick the sel_location from all_location for each sel_time(i). Since I
> have multiple(~20000) such tests, loop through both of them will be too
> time consuming.
>
> Should I sort both all_time and sel_time to descent/ascent order to
> speed it up?
>
> Thanks,
>
> Qian
> Qian
>

How about the usual trick of expanding the 1D array to 2D arrays,
for instance:

a = all_time # (fltarr(4000)+1)

b = (fltarr(10000)+1) # sel_time

c = abs(a - b)

w = where(c lt 0.001, count)

print,count

Of course, you'll want to decode these where results into the two
dimensions,
and then take the row as the index with which to access the alltime array.

for instance, something like:

selecteddata = all_location(*,wcols)





Cheers,
bob
Re: quick search of array [message #44570 is a reply to message #44569] Thu, 23 June 2005 12:33 Go to previous message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <1119544592.305102.257100@g49g2000cwa.googlegroups.com>,
tanqian@hotmail.com wrote:

> Hi,
>
> I have four arraies
>
> all_time = fltarr(10000)
> all_location = fltarr(3, 10000)
>
> sel_time = fltarr(4000)
> sel_location = fltarr(3,4000)
>
> the 'sel_time' is a subset of 'all_time'. Is there a quick way I could
> find index 'j' of all_time for each sel_time(i) (when
> abs(all_time(j)-sel_time(i)) lt 1e-5)? So I could use that index to
> pick the sel_location from all_location for each sel_time(i). Since I
> have multiple(~20000) such tests, loop through both of them will be too
> time consuming.
>
> Should I sort both all_time and sel_time to descent/ascent order to
> speed it up?

If you sort your arrays, you can use VALUE_LOCATE (a binary search) instead of
WHERE (an exhaustive search). Depending on circumstances, the speed difference
can be substantial.

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: quick search of array
Next Topic: Re: GeoTIFF tags and keys

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

Current Time: Sat Oct 11 14:59:05 PDT 2025

Total time taken to generate the page: 1.67418 seconds