I have an numpy array of numbers x and some thresholds [A,B,C,D]
I want to apply 5 different formulas to each of the slices of the array, but ideally I don't want to iterate over it (that's why I'm trying to use numpy).
What's the best way to do it? This is what I'm trying to do, is there a better way?
cond_A = np.where(x <= A)
cond_B = np.where((x > A) & (x <= B))
cond_C = np.where((x > B) & (x <= C))
cond_D = np.where((x > C) & (x <= D))
cond_E =np.where(x > D)
x[cond_A] = function_A(x[cond_A])
...
...
x[cond_E]= function_E(x[cond_E])
EDIT: If I try this I'm getting the error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()