nip.utils.maths.mean_for_unique_keys#
- nip.utils.maths.mean_for_unique_keys(data: ndarray, key: ndarray, axis: int = 0) ndarray [source]#
Compute the mean of values grouped by unique keys.
The two input arrays
data
andkey
should have the same shape. It is assumed that when two elements ofkey
are equal, the corresponding elements ofdata
should be equal. The function selects the unique keys fromkey
and computes the mean of the corresponding values indata
.- Parameters:
data (numpy.ndarray) – The values to aggregate.
key (numpy.ndarray) – The keys for each value. Must be broadcastable with
data
.axis (int, default=0) – The axis along which to compute the mean.
- Returns:
mean_values (numpy.ndarray) – The mean of the values for each unique key.