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

Home » Public Forums » archive » Calculating mean (was mean and sdev)
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
Calculating mean (was mean and sdev) [message #11042] Thu, 05 March 1998 00:00
Kevin Ivory is currently offline  Kevin Ivory
Messages: 71
Registered: January 1997
Member
Kevin Spencer wrote:
> they get rid of stdev in the first place? And calculating the mean
> is trivial; just use total(x)/n_elements(x).

It is not as trivial as that. If your array contains NaNs, you will
always get a NaN as a result. In many cases you will want to have
the mean of the finite values.

Another functionality I miss from many IDL routines is the possibility
to work on certain array dimensions without having to code loops
everywhere. The IDL function total offers this functionality, so
my function to code the mean looks like:

function average, array, dim, _extra=_extra
;+
; calculates the average value of an array (all arguments as in 'total')
; arguments
; array array to be averaged, any type except string
; dim dimension over which to average (see 'total' documentation)
; keywords
; _extra all keywords passed to 'total'
;-
if n_elements(dim) eq 0 then dim = 0
return, total(array, dim, _extra=_extra) / (total(finite(array), dim)>1)
end

Best regards
Kevin
--
Kevin Ivory Tel: +49 5556 979 434
Max-Planck-Institut fuer Aeronomie Fax: +49 5556 979 240
Max-Planck-Str. 2 mailto:Kevin.Ivory@linmpi.mpg.de
D-37191 Katlenburg-Lindau, GERMANY http://www.gwdg.de/~kivory2/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Function names (was mean and sdev)
Next Topic: NN IDL Freeware

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

Current Time: Fri Oct 10 16:04:22 PDT 2025

Total time taken to generate the page: 1.12212 seconds