landlab.data_record.aggregators¶
- aggregate_items_as_count(ids, size=None)[source]¶
Count the number of time an id appears in an array.
- Parameters:
- Returns:
The number of times each id appears.
- Return type:
ndarray of int
Examples
>>> from landlab.data_record.aggregators import aggregate_items_as_count >>> aggregate_items_as_count([1, 2, 3, 3, 1, 5]) array([0, 2, 1, 2, 0, 1]) >>> aggregate_items_as_count([1, 2, 3, 3, 1, 5], size=8) array([0, 2, 1, 2, 0, 1, 0, 0])
Negative ids are ignored.
>>> aggregate_items_as_count([1, 2, 3, 3, -1, 5]) array([0, 1, 1, 2, 0, 1])
- aggregate_items_as_mean(ids, values, weights=None, size=None)[source]¶
Find the mean of values associated with an id.
- Parameters:
ids (array_like of int) – An array of ids.
values (array_like) – The value associated with the corresponding id in the id array.
size (int, optional) – The size of the output array. This is useful if the ids array doesn’t contain all possible ids.
weights (Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None)
- Returns:
The mean of the values at each id.
- Return type:
ndarray of int
Examples
>>> from landlab.data_record.aggregators import aggregate_items_as_mean >>> aggregate_items_as_mean([0, 0, 1, 3, 4, 5], [1, 2, 3, 3, 1, 5]) array([1.5, 3. , 0. , 3. , 1. , 5. ]) >>> aggregate_items_as_mean([0, 0, 1, 3, 4, 5], [1, 2, 3, 3, 1, 5], size=8) array([1.5, 3. , 0. , 3. , 1. , 5. , 0. , 0. ])
Negative ids are ignored.
>>> aggregate_items_as_mean([0, -1, 1, 3, 4, 5], [1, 2, 3, 3, 1, 5]) array([1., 3., 0., 3., 1., 5.])
- aggregate_items_as_sum(ids, values, size=None)[source]¶
Find the sum of values associated with an id.
- Parameters:
- Returns:
The sum of the values at each id.
- Return type:
ndarray of int
Examples
>>> from landlab.data_record.aggregators import aggregate_items_as_sum >>> aggregate_items_as_sum([0, 0, 1, 3, 4, 5], [1, 2, 3, 3, 1, 5]) array([3., 3., 0., 3., 1., 5.]) >>> aggregate_items_as_sum([0, 0, 1, 3, 4, 5], [1, 2, 3, 3, 1, 5], size=8) array([3., 3., 0., 3., 1., 5., 0., 0.])
Negative ids are ignored.
>>> aggregate_items_as_sum([0, -1, 1, 3, 4, 5], [1, 2, 3, 3, 1, 5]) array([1., 3., 0., 3., 1., 5.])