So, lets say I have 100,000 float arrays with 100 elements each. I need the highest X number of values, BUT only if they are greater than Y. Any element not matching this
Settings elements below some threshold to zero is easy:
array = [ x if x > threshold else 0.0 for x in array ]
(plus the occasional abs() if needed.)
The requirement of the N highest numbers is a bit vague, however. What if there are e.g. N+1 equal numbers above the threshold? Which one to truncate?
You could sort the array first, then set the threshold to the value of the Nth element:
threshold = sorted(array, reverse=True)[N]
array = [ x if x >= threshold else 0.0 for x in array ]
Note: this solution is optimized for readability not performance.