How to get data in a histogram bin

后端 未结 2 724
鱼传尺愫
鱼传尺愫 2021-02-01 20:22

I want to get a list of the data contained in a histogram bin. I am using numpy, and Matplotlib. I know how to traverse the data and check the bin edges. However, I want to d

2条回答
  •  无人及你
    2021-02-01 21:00

    digitize, from core NumPy, will give you the index of the bin to which each value in your histogram belongs:

    import numpy as NP
    A = NP.random.randint(0, 10, 100)
    
    bins = NP.array([0., 20., 40., 60., 80., 100.])
    
    # d is an index array holding the bin id for each point in A
    d = NP.digitize(A, bins)     
    

提交回复
热议问题