python - Put N points into M equal bins -
i have array n (positive) points. find m bin edges of histogram such bars have same height. in other words want find m+1 points such count of array points between 2 consecutive bin edges same.
example
>>> array = [0.3 0.3 0.3 0.7 0.8 0.9] >>> m = 2 >>> binpartition(array, m) [0, 0.5, 1]
i appreciate answer in python , numpy link known algorithm suffice! thank you! :)
than can done percentile
:
import numpy np def binpartition(array, m): return np.percentile(array, np.linspace(0, 100, m + 1)) binpartition([0.3, 0.3, 0.3, 0.7, 0.8, 0.9], 2) >>> array([ 0.3, 0.5, 0.9])
Comments
Post a Comment