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

Home » Public Forums » archive » Re: avoiding for loop when calculating median
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: avoiding for loop when calculating median [message #10961 is a reply to message #10952] Fri, 30 January 1998 00:00 Go to previous messageGo to previous message
a2652099 is currently offline  a2652099
Messages: 10
Registered: August 1996
Junior Member
george.mccabe@gsfc.nasa.gov (George McCabe) wrote:

> calculating the median of each i set of values M(i,*), I would like to
> 'vectorize' the operation to avoid a FOR loop like the following -
>
> for cnt=0,idim-1 do begin
> calcmedian(cnt)=median(mat(cnt,*))
> end
>
> but, you can't do -
>
> cnt=indgen(idim)
> calcmedian(cnt)=median(M(cnt,*))
>
> and get the desired result, where each element of calcmedian() will be
> assigned the same value.
>
> can it be done wothout a FOR loop?

I don't think so. But maybe the routine above can be made a bit faster?

I assume that mat is an idim x jdim array. mat(cnt,*) gives the elements
no. cnt, cnth+idim, cnth+2*idim etc., I guess it's easier to use
mat2=reform(mat), so all the elements are in line.

Another idea:

index = lindgen( jdim )
for cnt = 0, idim-1 do begin
calcmedian(cnt) = median( mat2(cnt*jdim+index) )
end

Whether there will be a measurable improvenment in speed will depend on
the sizes of idim and jdim.

Alex
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: LMFIT -- stay away from it!
Next Topic: REAL DATA

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

Current Time: Fri Oct 10 12:54:32 PDT 2025

Total time taken to generate the page: 0.71778 seconds