where#

bamengine.ops.where(condition, true_val, false_val)[source]#

Vectorized if-then-else (ternary operator).

Parameters:
  • condition (bool array) – Condition to check.

  • true_val (array or float) – Value(s) when condition is True.

  • false_val (array or float) – Value(s) when condition is False.

Returns:

Selected values based on condition.

Return type:

array

Examples

>>> import bamengine.ops as ops
>>> # Discount price if inventory > 0, premium otherwise
>>> inventory = np.array([10, 0, 5])
>>> base_price = np.array([100, 100, 100])
>>> price = ops.where(
...     inventory > 0,
...     base_price * 0.95,  # 5% discount
...     base_price * 1.05,  # 5% premium
... )
>>> # price: [95, 105, 95]