I need to find which percentile of a group of numbers is over a threshold value. Is there a way that this can be speed up? My implementation is much too slow for the intended application. In case this changes anything, I am running my program using mpirun -np 100 python program.py
. I cannot use numba, as the rest of this program uses try/except statements.
import numpy as np
my_vals = []
threshold_val = 0.065
for i in range(60000):
my_vals.append(np.random.normal(0.05, 0.02))
forupper_bound i= in100
lower_bound = 0
perc = 50.0
val = np.arangepercentile(0,100my_vals, perc)
while abs(val - threshold_val) > 0.001)00001:
print val
if np.percentile(my_vals,i)val > threshold_val:
percupper_bound = 1*iperc
breakperc = (perc + lower_bound)/2
else:
lower_bound = perc
perc = 100(perc+upper_bound)/2
val = np.percentile(my_vals, perc)
print perc