user393144 - 1 year ago 172

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?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

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

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**