Calculating mean (was mean and sdev) [message #11042] |
Thu, 05 March 1998 00:00 |
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/
|
|
|