- qspec. average ( a , std=None , cov=None , axis=None )[source]
-
The (weighted) average of a sample and its standard error
$$\begin{aligned} \bar{a} &= \frac{\sum_i w_ia_i}{\sum_i w_i},\quad w_i = \frac{1}{\Sigma_{ii}}\\[1ex] \sigma_{\bar{a}}^2 &= \frac{\sum_{ij} w_iw_j\Sigma_{ij}}{\left(\sum_i w_i\right)^2}, \end{aligned}$$with the covariance matrix $\Sigma$ given by
covor by $\Sigma_{ij} = \delta_{ij}\sigma_i^2$ ifstdis given. If neither is given, the arithmetic mean and the standard error of the mean are returned.- Parameters:
-
- aarray_like
The sample data.
- stdarray_like | None
An array of standard deviations associated with the values in
a. If specified, the weighted average of the uncorrelated sample data and its standard error is returned.- covscalar_nd | None
The covariance matrix associated with the values in
a. If specified, it overridesstdand the weighted average of the correlated sample data and its standard error is returned. If no axis is specified,covmust have shape(a.size, a.size)with elements associated with the values in the flatteneda, otherwisecovmust have either shape(a.shape[axis], a.shape[axis])or(..., a.shape[axis - 1], a.shape[axis], a.shape[axis], a.shape[axis + 1], ...).- axisint_like | None
The axis along which the average is computed. If
None,ais flattened.
- Returns:
- Raises:
-
- ValueError
If the shapes of
aandcovdo not match.