Anonymous user
Averages/Arithmetic mean: Difference between revisions
m
Lang tags
m (F# added List.average) |
m (Lang tags) |
||
Line 3:
=={{header|Ada}}==
This example shows how to pass a zero length vector as well as a larger vector.
Put(Item => Mean(A), Fore => 1, Exp => 0);
Output:
3.83333
Line 37:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - note that some necessary LONG REAL operators are missing from ELLA's library.}}
<lang algol68>
PROC mean = (REF[]REAL p)REAL:
# Calculates the mean of qty REALs beginning at p. #
Line 51:
print((mean(test),new line))
)
</
=={{header|AmigaE}}==
Line 111:
=={{header|APL}}==
{{works with|APL2}}
<lang apl> X←3 1 4 1 5 9
=={{header|BASIC}}==
{{works with|QuickBasic|4.5}}
Assume the numbers are in a DIM named nums.
=={{header|C}}==
Line 211:
=={{header|Common Lisp}}==
=={{header|D}}==
Using template to make the mean function work for higher-rank array.
<
import std.stdio ;
Line 246:
writefln("array : ", array.mean()) ;
writefln("multi : ", multi.mean()) ;
}</
=={{header|E}}==
Line 298:
=={{header|F_Sharp|F#}}==
The following computes the running mean using a tail-recursive approach. If we just sum all the values then divide by the number of values then we will suffer from overflow problems for large lists. See [http://en.wikipedia.org/wiki/Moving_average wikipedia] about the moving average computation.
Checking this:
Line 331:
=={{header|Haskell}}==
This function works if the element type is an instance of Fractional:
But some types, e.g. integers, are not Fractional; the following function works for all Real types:
=={{header|IDL}}==
Line 343:
If truly only the mean is wanted, one could use
<lang idl> x = [3,1,4,1,5,9]
But <tt>mean()</tt> is just a thin wrapper returning the zeroth element of <tt>moment()</tt> :
which are mean, variance, skewness and kurtosis.
Line 358:
=={{header|J}}==
That is, sum divided by the number of items. The verb also works on higher-ranked arrays. For example:
<lang j> mean 3 1 4 1 5 9
The computation can also be written as a loop. It is shown here for comparison only and is highly non-preferred compared to the version above.
=={{header|Java}}==
{{works with|Java|1.5+}}
Assume the numbers are in a double array called "nums".
<lang java5>...
=={{header|JavaScript}}==
{{libheader|Functional}}
}</lang>
=={{header|Logo}}==
=={{header|Lucid}}==
=={{header|M4}}==
Line 440 ⟶ 442:
=={{header|MAXScript}}==
=={{header|Nial}}==
in the standard way, mean is
but it fails with 0 length vectors. so using a tally with a minimum value 1
=0</lang>
=={{header|OCaml}}==
Line 709 ⟶ 711:
=={{header|V}}==
].</lang>
|