Logo

Programming-Idioms

History of Idiom 203 > diff from v1 to v2

Edit summary for version 2 by spectrum:
New Fortran implementation by user [spectrum]

Version 1

2019-09-28, 20:40:49

Version 2

2019-09-28, 21:30:19

Idiom #203 Calculate mean and standarddeviation

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

Idiom #203 Calculate mean and standarddeviation

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

Code
real, allocatable :: data(:)
real :: m, s
...
m = sum( data ) / size( data )
s = sqrt( sum( data**2 ) / size( data ) - m**2 )
Comments bubble
data may be a multidimensional array (e.g. data(:,:)).