Random Number from Histogram
It’s probably what np.random.choice does in @Ophion’s answer, but you can construct a normalized cumulative density function, then choose based on a uniform random number: from __future__ import division import numpy as np import matplotlib.pyplot as plt data = np.random.normal(size=1000) hist, bins = np.histogram(data, bins=50) bin_midpoints = bins[:-1] + np.diff(bins)/2 cdf = np.cumsum(hist) cdf = … Read more