Lets say I got 4 numpy arrays of shape (1000,1000):
a1, a2, a3, a4...
I would like fill a4 with different values and conditions based on the other 3 arrays.
For example (a basic example, made for the purposes of the question):
if a1 < a2:
a4 = a3 / a2
elif a2 = a1:
a4 = a1: a4 = a2 + a1
else:
if a3 < a1:
a4 = a1 * a2 * a3
else:
a4 = a1 / a2 - a3
What is the proper and the most effective way to fill a4 properly? np.where seems to be invalid way, as it's hard to implement condition inside a condition... Should I use np.putmask() multiple times? won't it make it really slow? (something like below)
np.putmask(a4,(a1 < a2),a3 / a2)
np.putmask(a4,(a2 = a1),a2 + a1)
np.putmask(a4,!((a2 = a1) & (a1 < a2)) & (a3 < a1),a1 * a2 * a3)
np.putmask(a4,!((a2 = a1) & (a1 < a2)) & (a3 < a1),a1 / a2 - a3)
Is there any other way?
Basically I got a task to turn some complex math formulas with multiple cross-overing conditions based on single values to the ones based on whole arrays of these numbers.
else ifis not valid python and theelse:branch could be written as a secondelif: ... else:. To chain multipleifelifyou can usenp.select. It would be easier to help with example input und expected output data.np.selectdoesn't seem to help in that task, it just selects elements, I need to do math on arrays, whole onesnp.selectis not the choice. Something likenp.select((a1<a2, a2==a1), (a3/a2, a2+a1))?