sum#

bamengine.ops.sum(a, axis=None, where=None)[source]#

Sum array elements, optionally over axis or subset.

Parameters:
  • a (array) – Input array.

  • axis (int, optional) – Axis to sum over. If None, sum all elements.

  • where (bool array, optional) – Mask for subset to sum over.

Returns:

Sum of array elements (scalar if axis=None, array otherwise).

Return type:

float or array

Examples

>>> import bamengine.ops as ops
>>> production = np.array([10, 20, 30, 0])
>>> # Total production
>>> total = ops.sum(production)
>>> # total: 60
>>>
>>> # Production only from active firms
>>> active = production > 0
>>> active_total = ops.sum(production, where=active)
>>> # active_total: 60