def weighted_sample(weights, objects):
    """
    Return a random item from objects, with the weighting defined by weights
    (which must sum to 1).
    """
    # An array of the weights, cumulatively summed.
    cs = np.cumsum(weights)
    # Find the index of the first weight over a random value.
    idx = sum(cs < np.random.rand())
    return objects[idx]


# compute softmax for each row
dataset/ETHPy150Open rllab/rllab/rllab/misc/special.py/weighted_sample/original