ak.mean — Awkward Array 2.8.2 documentation (original) (raw)

Defined in awkward.operations.ak_mean on line 29.

ak.mean(x, weight=None, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None)#

Parameters:

Computes the mean in each group of elements from x (many types supported, including all Awkward Arrays and Records). The grouping is performed the same way as for reducers, though this operation is not a reducer and has no identity. It is the same as NumPy’smeanif all lists at a given dimension have the same length and no None values, but it generalizes to cases where they do not.

Passing all arguments to the reducers, the mean is calculated as

ak.sum(x*weight) / ak.sum(weight)

For example, with an array like

array = ak.Array([[0, 1, 2, 3], [ ], [4, 5 ]])

The mean of the innermost lists is

ak.mean(array, axis=-1) <Array [1.5, nan, 4.5] type='3 * float64'>

because there are three lists, the first has mean 1.5, the second is empty, and the third has mean 4.5.

The mean of the outermost lists is

ak.mean(array, axis=0) <Array [2, 3, 2, 3] type='4 * float64'>

because the longest list has length 4, the mean of 0 and 4 is 2.0, the mean of 1 and 5 is 3.0, the mean of 2 (by itself) is 2.0, and the mean of 3 (by itself) is 3.0. This follows the same grouping behavior as reducers.

See ak.sum for a complete description of handling nested lists and missing values (None) in reducers.

See also ak.nanmean.