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
dataandkeyshould have the same shape. It is assumed that when two elements ofkeyare equal, the corresponding elements ofdatashould be equal. The function selects the unique keys fromkeyand 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.