I have the following four arrays with identical shape:
a = np.array([12, 6, 7])
b = np.array([2, 3, 3])
c = np.array([5, 4, 9])
d = np.array([15, 22, 28])
As long as the condition num > 20 is met for each element in d, I want to multiply a by b and replace the values in c with the individual result of that multiplication. So, c would be equal to [5, 18, 21].
My attempt:
c[d > 20] = a[d > 20] * b[d > 20]
Is there any way to implement this more efficiently for large arrays?