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

Home » Public Forums » archive » mean() function
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: mean() function [message #46952 is a reply to message #46938] Mon, 16 January 2006 02:27 Go to previous messageGo to previous message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
Hi,

one small correction: instead of n_elements(...) you should use
n_elements(...)-1.

This approach has an other problem: the elements at the beginning of the
array are divided ~n_elements() times, which can introduce large rounding
errors.

Example:

IDL> print, !version
print, !version
{ x86 linux unix linux 6.2 Jun 20 2005 32 64}

IDL> a=fltarr(10000000l)
IDL> a[0]=1.0e7
IDL> print, alt_mean(a)
1.02190

vs.

IDL> print, mean(a)
% Compiled module: MEAN.
% Compiled module: MOMENT.
1.00000


there is no golden way :-)))

regards,
lajos


On Mon, 16 Jan 2006, Maarten wrote:

> I think that this comes close. I ignores infinite numbers on request.
> Is it fast: no. But implementing the thing is C should be near trivial
> if you have dealt with that before (I haven't, at least not in IDL).
>
> function alt_mean, D, nan=nan
> compile_opt defint32, strictarr, logical_predicate, strictarrsubs
>
> M = 0.0
>
> if keyword_set(nan) then begin
> idx = where(finite(D), cnt)
> if cnt gt 0 then begin
> for ii=0,n_elements(idx) do $
> M += (D[idx[ii]] - M)/(ii+1)
> endif else begin
> M = !values.d_nan
> endelse
> endif else begin
> for ii=0,n_elements(D) do $
> M += (D[ii] - M)/(ii+1)
> endelse
>
> return, M
> end
>
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: mean() function
Next Topic: ASP.NET vs JSF

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

Current Time: Fri Oct 10 05:52:55 PDT 2025

Total time taken to generate the page: 0.71952 seconds