The use of this normalization algorithm ensures that all elements of the input vector are transformed into the output vector in such a way that the mean of the output vector is approximately Zero, while the standard deviation (as well as the variance) are in a range close to unity.

We calculate the mean of all elements of a vector as:

The standard deviation can be expressed as:

The use of this formula depends on a pre-calculated . From a programmer’s point of view, the following equivalent formula would be computationally less expensive, since it requires only one iteration over the input vector:

We transform the input vector **x** into the (normalized) output vector **x’** by applying the following algorithm:

yielding for the output vector the conditions:

### Sample

### C++-Code

```
// normalize input vector idata
// to output vector odata with
// zero mean and unit variance
BOOL norm_zmuv (
vector<double>& idata, // input array
vector<double>& odata, // output array
double& mean, // returns mean of idata
double& sigma) // returns sigma of idata
{
ULONG x = 0;
double sx = 0;
double sxx = 0;
double n = idata.size();
mean = 0;
sigma = 0;
if ( n == 0 )
return false;
for ( x = 0; x < n; x++ )
{
sx += idata[x];
sxx += sqr(idata[x]);
}
mean = sx / n;
sigma = sqrt ( (n*sxx - sqr(sx)) / (n*(n-1)) );
// paranoia check
if ( sigma == 0 )
return false;
// clear the output vector
odata.clear();
// pre-allocate memory
odata.resize(idata.size());
for ( x = 0; x < n; x++ )
odata[x] = (idata[x] - mean) / sigma;
return true;
}
```