This language bar is your friend. Select your favorite languages!

Idiom #203 Calculate mean and standarddeviation

Calaculate m, the mean and s, the standard deviation of data, an array of floating point values.

m  = data.sum / data.length.to_f
sd = Math.sqrt data.sum { |n| (m-n)**2 } / data.length.to_f 
real, allocatable :: data(:)
real :: m, s
...
m = sum( data ) / size( data )
s = sqrt( sum( data**2 ) / size( data ) - m**2 )
math
var
  m, s: double;
  data: array of double;
...
  MeanAndStdDev(data, m, s);
...
use Statistics::Lite qw(mean stddev);
my $m = mean @data;
my $s = stddev @data;

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Bart