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

Home » Public Forums » archive » Re: Using MIN on arrays : Exorcising loops?
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: Using MIN on arrays : Exorcising loops? [message #27059 is a reply to message #27058] Fri, 05 October 2001 06:03 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Andrew Cool <cooladjc@chariot.net.au> writes:

> Hi all,
>
> I have three slabs of data [640,500] held as an array [640,500,3].
>
> I need to populate another 2D array [640,500] with the minimum
> value for every x,y coordinate found in the first 3 arrays.
>
> At the moment my code loops something like this :-
>
> data_array = Fltarr(640,500,3)
> Min_array = Fltarr(640,500)
>
> For x = 0,639 Do Begin
> For y = 0,249 Do Begin
> Min_array(x,y) = MIN(data_array(x,y,*))
> End
> End
>
> There's gotta be a better way, surely? Some syntax variant on MIN?
> Histogram even? ;-)

Hi Andrew--

This is a pretty good question, and "no," I don't think there is a way
to do it with the MIN() function alone. I have a routine called
CMAPPLY on my web page which can do this kind of thing, but it won't
be terribly efficient here because it still does a loop based on the
number of output elements, so it is exactly the same as the loop you
posted above.

Still there is a trivial way to solve this using the threshold
operator. I have always advocated that loops are not "bad," rather
the poor use of loops is bad. :-) The trick here is to put the most
expensive operation -- operating on an image worth of data -- at the
center of your loop.

How does this work for you?

data_array = Fltarr(640,500,NZ)
Min_array = data_array(*,*,0)

for i = 1, NZ-1 do $
min_array = min_array < data_array(*,*,i)

Since NZ is 3, this really only has three iterations, and most of the
work is done by the "<" operator, which is the same as MIN().

Hmm, maybe I should put something like this in CMAPPLY...

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
Read Message
Read Message
Previous Topic: Re: CURSOR question
Next Topic: Re: Possibly O/T: printing IDL code in colour -> CAN DO!!!

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

Current Time: Wed Oct 08 17:03:10 PDT 2025

Total time taken to generate the page: 0.00448 seconds