Re: Functions to calculate the arithmetic mean and geometric mean of an array?

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sun Oct 14 2012 - 08:28:34 MDT

No, NCL does not have a geometric mean function.

You can always write your own function.

---
undef ("geometric_mean")
function geometric_mean(x:numeric)
;
; Mathematical definition: The nth root of the product of n numbers.
; Practical definition:    The average of the logarithmic values of a 
data set,
;                          converted back to a base 10 number.
;
; The geometric mean applies only to positive numbers
local n, gmean
begin
   gmean = 0d0                   ; force double
   if (isatt(x,"_FillValue") .and. all(ismissing(x)) ) then
       gmean = x@_FillValue
       return(gmean)
   end if
   if (any(x.le.0)) then         ; numbers > 0 only
       gmean = getFillValue(x)
       return(gmean)
   end if
   n  = num(.not.ismissing(x))
  ;n  = product( dimsizes(x) )
   if (typeof(x).eq."double") then
       gmean = exp(avg(log(x)))
      ;gmean = product(x)^(1.d0/n)
   else
       gmean = exp(avg(log(x*1d0)))
      ;gmean = product(x*1d0)^(1.d0/n)
   end if
   gmean@opt = "geometric mean"
   return(gmean)
end
On 10/13/12 5:48 PM, Wen.J.Qu wrote:
> Hi, all
> Is there any functions to calculate the arithmetic mean and geometric
> mean of an array? I think the function "avg" seems can do the arithmetic
> mean. How about the geometric mean?
> Thanks a lot in advance.
> Shawn?
> ------------------------------------------------------------------------
> Wen.J.Qu
> 2012-10-13
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Oct 14 08:28:47 2012

This archive was generated by hypermail 2.1.8 : Tue Oct 23 2012 - 11:10:05 MDT