make_cond#
- class brainpy.math.make_cond(true_fun, false_fun, dyn_vars=None)[source]#
Make a condition (if-else) function.
Examples
>>> import brainpy.math as bm >>> a = bm.zeros(2) >>> b = bm.ones(2) >>> >>> def true_f(x): a.value += 1 >>> def false_f(x): b.value -= 1 >>> >>> cond = bm.make_cond(true_f, false_f, dyn_vars=[a, b]) >>> cond(True) >>> a, b (Array([1., 1.], dtype=float32), Array([1., 1.], dtype=float32)) >>> cond(False) >>> a, b (Array([1., 1.], dtype=float32), Array([0., 0.], dtype=float32))
- Parameters:
- Returns:
cond_func – The condictional function receives two arguments:
pred
for true/false judgement andx
for external input.- Return type:
ControlObject