In [1]:
import (
	"math"
	"sort"

	"gonum.org/v1/gonum/stat"
)

Out[1]:
In [3]:
xs := []float64{
	32.32, 56.98, 21.52, 44.32,
	55.63, 13.75, 43.47, 43.34,
	12.34,
}

printf("data: %v\n", xs)
data: [32.32 56.98 21.52 44.32 55.63 13.75 43.47 43.34 12.34]
Out[3]:
In [6]:
// computes the weighted mean of the dataset.
// we don't have any weights (ie: all weights are 1)
// so we just pass a nil slice.
mean := stat.Mean(xs, nil)
variance := stat.Variance(xs, nil)
stddev := math.Sqrt(variance)

Out[6]:
In [8]:
// stat.Quantile needs the input slice to be sorted.
sort.Float64s(xs)
printf("data: %v (sorted)\n", xs)
data: [12.34 13.75 21.52 32.32 43.34 43.47 44.32 55.63 56.98] (sorted)
Out[8]:
In [13]:
// computes the median of the dataset.
// here as well, we pass a nil slice as weights.
median := stat.Quantile(0.5, stat.Empirical, xs, nil)

printf("mean=     %v\n", mean)
printf("median=   %v\n", median)
printf("variance= %v\n", variance)
printf("std-dev=  %v\n", stddev)
mean=     35.96333333333334
median=   43.34
variance= 285.306875
std-dev=  16.891029423927957
Out[13]: