user393144 - 1 year ago 82

C++ Question

Is there a way to calculate mean and standard deviation for a vector containing samples using boost?

Or do I have to create an accumulator and feed the vector into it?

Answer Source

Using accumulators **is** the way to compute means and standard deviations in boost.

```
accumulator_set<double, stats<tag::variance> > acc;
for_each(a_vec.begin(), a_vec.end(), bind<void>(ref(acc), _1));
cout << mean(acc) << endl;
cout << sqrt(variance(acc)) << endl;
```