python - numpy sort top bottom -
i trying pull top 5%, bottom 5% , remaining out separate arrays , save average. code below.
tg = 48000000 element float array tg.sort() pct = int(tg.size*0.05) high5 = tg[-pct:].mean() low5 = tg[:pct].mean() mid90 = tg[pct:-pct].mean()
i'd appreciate suggestions on how speed up.
actually don't need sort array. use partition method:
tg = 48000000 element float array pct = int(tg.size*0.05) tg.partition([pct, tg.size - pct]) mean_low5 = tg[:pct].mean() mean_high5 = tg[-pct:].mean() mean_mid90 = tg[pct:-pct].mean()
(code updated according jaime' comment)
Comments
Post a Comment