Hi, Dennis
Thank you very much for the function to to calculate the geometric mean. It works quite well, I also learn a lot of other functions and methods to do other calculations.
Thank you again for your kind help.
All my best!
Shawn
Wen.J.Qu
2012-10-14
发件人: Dennis Shea
发送时间: 2012-10-14 09:28:40
收件人: Wen.J.Qu@gmail.com
抄送: ncl-talk
主题: Re: [ncl-talk] Functions to calculate the arithmetic mean and geometricmean of an array?
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 14:53:13 2012
This archive was generated by hypermail 2.1.8 : Tue Oct 23 2012 - 11:10:04 MDT