def sample_discrete(values, weights, size=1):
    weights = np.array(weights)
    if weights.ndim == 1:
        return np.random.choice(values, size=size, p=weights)
    else:
        return np.fromiter(map(lambda t: np.random.choice(values, p=t), weights), dtype='int')
Generate a sample of given size, given a probability mass function.
dataset/ETHPy150Open pgmpy/pgmpy/pgmpy/utils/mathext.py/sample_discrete