Use numpy.select
, which lets you select from multiple conditions:
conds = [r <= p1, r <= (p1 + p2), r > (p1 + p2)]
choices = [a1, a2, a3]
a = np.select(conds, choices)
In your case, the third condition could actually be any condition that evaluates to True (e.g., r == r
).