Radar · Go · Archive · Week 12 · Mar 17 – 23, 2025
x/exp/stats – new statistics package
Worth knowingecosystem
- What changed
- The proposal adds a
golang.org/x/exp/statspackage providingMean,MeanAndStdDev, andMedianfunctions for floating‑point slices. The API is documented, and the functions panic on empty slices. - Production impact
- The source does not say.
- Try it
go get golang.org/x/exp/statsand callstats.Mean([]float64{1,2,3}).- Source
- github.com/golang/go/issues/69264
Understand it, then run it
The change adds a new package golang.org/x/exp/stats that gives three simple statistical functions: Mean, MeanAndStdDev, and Median. These functions work on slices of floating‑point numbers and return a single value or a pair of values. If you give an empty slice the function panics, so you should check that the slice has at least one element before calling. The functions do not modify the slice you pass in, and they handle special floating‑point values like NaN and Inf according to the rules described in the documentation.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed