divide#

bamengine.ops.divide(a, b, out=None)[source]#

Divide two arrays or array and scalar (safe - avoids division by zero).

Automatically replaces zeros in denominator with small epsilon (1e-10).

Parameters:
  • a (array) – Numerator array.

  • b (array or float) – Denominator array or scalar.

  • out (array, optional) – Output array.

Returns:

Result of division (a / b).

Return type:

array

Examples

>>> import bamengine.ops as ops
>>> wage_bill = np.array([100.0, 200.0, 0.0])
>>> production = np.array([10.0, 0.0, 0.0])  # Some zeros!
>>> # Safe division - no divide by zero errors
>>> unit_cost = ops.divide(wage_bill, production)
>>> # unit_cost: [10.0, very_large, 0.0]

Notes

This function is safer than NumPy’s divide as it prevents division by zero errors by replacing zero denominators with 1e-10. Negative denominators are preserved.