group_by

mdtools.numpy_helper_functions.group_by(keys, values, assume_sorted=False, return_keys=False, debug=False)[source]

Group the elements of values by their keys.

Parameters
  • keys (array_like) – 1-dimensional array of keys used to group the element of values.

  • values (array_like) – The values (elements) to be grouped by keys.

  • assume_sorted (bool, optional) – If True, the key-value pairs are assumed to be sorted with respect to the keys, which can speed up the calculation.

  • return_keys (bool, optional) – If True, return the unique, sorted keys.

  • debug (bool, optional) – If True, check the input arguments.

Returns

  • unique_keys (numpy.ndarray) – The unique, sorted keys. Only returned, if return_keys is True.

  • grouped_values (list of numpy.ndarrays) – List of numpy.ndarrays, one array for all elements of values belonging to the same key. The arrays in the list are sorted according to the unique, sorted keys.