I have one numpy array that stores the thresholds and another array that store some values. I want these last values to be less or equal of the corresponding thresholds. In particular, if a value is greater than its corresponding threshould I should change it with the thresholds.
The following example gives exactly what I want but I'm wondering if exist a better way to implement it or if already exist a numpy method (that I searched for but that I didn't find) to do it.
In [1]: import numpy as np
In [2]: a = np.random.rand(10)
In [3]: a
Out[3]:
array([0.38331068, 0.32042463, 0.89980916, 0.86472908, 0.10812789,
0.35855107, 0.09916983, 0.55710449, 0.38591185, 0.70798023])
In [4]: t = np.array([0.95, 0.9, 0.8, 0.75, 0.7, 0.65, 0.6, 0.55, 0.5, 0.45])
In [5]: mask = a > t
In [6]: a[mask] = t[mask]
In [7]: a
Out[7]:
array([0.38331068, 0.32042463, 0.8 , 0.75 , 0.10812789,
0.35855107, 0.09916983, 0.55 , 0.38591185, 0.45 ])