Divide a list into multiple lists based on a bin size

前端 未结 6 602
悲哀的现实
悲哀的现实 2021-01-18 03:02

I have a list containing more than 100,000 values in it.

I need to divide the list into multiple smaller lists based on a specific bin width say 0.1. Can anyone hel

6条回答
  •  长情又很酷
    2021-01-18 03:32

    Is this what you want? (Sample output would have been helpful :)

    f = [-0.234, -0.04325, -0.43134, -0.315, -0.6322, -0.245, 
         -0.5325, -0.6341, -0.5214, -0.531, -0.124, -0.0252]
    
    import numpy as np
    data = np.array(f)
    hist, edges = np.histogram(data, bins=10)
    print hist
    

    yields:

     [2 3 0 1 0 1 2 0 1 2]
    

    This SO question assigning points to bins might be helpful.

提交回复
热议问题