Question

Given an array V of doubles the goal is to compute the average A.

The usually recommended solution is something like:

double A = V[0];
for (int i = 1; i<N; i++)
{
    A = ((A * i) + V[i]) / (i + 1.0);
}

Computing an average of an array seems to be a common operation, yet I fail to find a function that would do that in a vectorized fashion.

All I found in vDSP is the vavlinD function which computes arrays of averages, and cannot be retrofitted to compute the average of a single array.

Was it helpful?

Solution

Found the right function in vDSP. It is vDSP_meanv.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top