If I have bin edges and counts for each bin, is there a nice succinct way to sample from the probability density function this implies?
Here is an example of what I mean.
bin_edges = [0,2.1,6.3,23.5]
counts = [5,2,10]
The probability density function is a step function with steps at:
[0,2.1,6.3,23.5]
and the probability density (height of the step) for the first step is 5/(17* 2.1). The probability density for the second bin/step is 2/(17*4.2), the probability density the third step/bin is 10/(17*17.2).
If you fall in a bin/step the value you sample is uniformly sampled from the x-values of the step. So if you fall in the first step it is uniform between 0 and 2.1.
Is there a succinct way of performing this sampling using a Python module? For example using scipy/numpy/etc?

