mean#

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

Calculate mean, optionally over axis or subset.

Parameters:
  • a (array) – Input array.

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

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

Returns:

Mean value (scalar if axis=None, array otherwise).

Return type:

float or array

Examples

>>> import bamengine.ops as ops
>>> prices = np.array([100, 110, 90, 0])
>>> # Average price of active firms (price > 0)
>>> active = prices > 0
>>> avg_price = ops.mean(prices, where=active)
>>> # avg_price: 100