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 #27052 is a reply to message #27046] Fri, 05 October 2001 09:56 Go to previous messageGo to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
"Liam E. Gumley" wrote:
>
> Dick Jackson wrote:
>>
>> "Andrew Cool" <cooladjc@chariot.net.au> wrote in message
>> news:3BBD96E8.B1329549@chariot.net.au...
>>> 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.
>>>
>>> [...]
>>>
>>> There's gotta be a better way, surely? Some syntax variant on MIN?
>>
>> It sure would be nice if MIN and MAX had a Dimension parameter, just like
>> TOTAL has. It would be even nicer if it were coming in 5.5, to be released
>> Any Day Now, wouldn't it? Too bad that anyone who would know about this
>> would be bound by a non-disclosure agreement. ;-|
>
> In other words, it sure would be nice if IDL could do something like
> this:
>
> IDL> a = indgen(2, 5)
> IDL> print, a
> 0 1
> 2 3
> 4 5
> 6 7
> 8 9
> IDL> print, min(a, dim=2)
> 0 1
> IDL> print, min(a, dim=1)
> 0 2 4 6 8
>
> where the DIM keyword is the dimension number, starting at dimension 1.
> Maybe this will be supported by MIN and MAX in the not too distant
> future ;-)

Here's hoping. Fortran 90/95 has intrinsics MINVAL and MAXVAL that do exactly that and they're
quite handy. I use 'em all the time.


program test_minmaxval

implicit none
integer, parameter :: n = 2, m = 5
integer, dimension( n,m ) :: a
integer :: i

a = reshape( (/ (i, i = 0, n*m - 1 ) /),(/ n,m /) )

print *, 'Print a:'
print *, a

print *, 'Print minval( a, dim = 2 ):'
print *, minval( a, dim = 2 )
print *, 'Print minval( a, dim = 1 ):'
print *, minval( a, dim = 1 )

end program test_minmaxval


lnx142:/usr1/pvandelst/tmp/f90_Test : pgf90 test_minmaxval.f90
lnx142:/usr1/pvandelst/tmp/f90_Test : a.out
Print a:
0 1 2 3 4 5
6 7 8 9
Print minval( a, dim = 2 ):
0 1
Print minval( a, dim = 1 ):
0 2 4 6 8

Oh, oops. Sorry, I thought this was comp.lang.fortran.... :o)

ehem...

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
[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 19:04:43 PDT 2025

Total time taken to generate the page: 0.01684 seconds