Signature
np.mean(a, axis=None, keepdims=False, dtype=None)What it does
np.mean adds the selected values and divides by their count. It is the arithmetic average, not a median or a weighted mean.
Parameters
aarray_like- The values to average.
axisint or tuple of ints, optionaloptional- The axis or axes to collapse.
keepdimsbool, optionaloptional- Preserve collapsed axes as length-one dimensions.
Returns
ndarray or scalar
Example
pythonnp.mean example
import numpy as np
scores = np.array([[80, 90, 70], [60, 75, 85]])
print(scores.mean(axis=1))Output
[80. 73.33333333]
Watch out for
- The mean is sensitive to outliers; inspect the distribution before summarizing.
- An empty array produces a warning and a NaN result.