user393144 - 6 months ago 41

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

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;
```