Python: Checking to which bin a value belongs
Probably too late, but for future reference, numpy has a function that does just that: http://docs.scipy.org/doc/numpy/reference/generated/numpy.digitize.html >>> my_list = [3,2,56,4,32,4,7,88,4,3,4] >>> bins = [0,20,40,60,80,100] >>> np.digitize(my_list,bins) array([1, 1, 3, 1, 2, 1, 1, 5, 1, 1, 1]) The result is an array of indexes corresponding to the bin from bins that each element from my_list … Read more