I have a numpy.ndarray X. I want to find all the places in X that X>threshold, and then do X=threshold.
What is the cheapest way (in terms of time-complexity) to do this? I need to run this procedure millions of times. Thanks!
I have a numpy.ndarray X. I want to find all the places in X that X>threshold, and then do X=threshold.
What is the cheapest way (in terms of time-complexity) to do this? I need to run this procedure millions of times. Thanks!
As far as I know, you can use the numpy indexing in order to replace all elements that bigger than some threshold.
Although, I'm not sure it's the fastest way.
threshold = 10 # for example
some_array[some_array > threshold] = threshold
try numpy.where:
from numpy import where
Y = where( X> treshold, threshold,X)
where applies and if statement in the ufunc-manner with where( condition, if True, else )