nip.utils.maths.mean_for_unique_keys

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 and key should have the same shape. It is assumed that when two elements of key are equal, the corresponding elements of data should be equal. The function selects the unique keys from key and computes the mean of the corresponding values in data.

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.