I have an array of probabilities, and I want to use those probabilities to generate an array of picked values, each value picked with the corresponding probability.
Example:
in: [ 0.5, 0.5, 0.5, 0.5, 0.01, 0.01, 0.99, 0.99]
out: [ 0, 1, 1, 0, 0, 0, 1, 1]
I'd like to use numpy native functions for this, rather than the following loop:
array_of_probs = [0.5, 0.5, 0.5, 0.5, 0.01, 0.01, 0.99, 0.99]
results = np.zeros(len(array_of_probs))
for i, probs in enumerate(array_of_probs):
results[i] = np.random.choice([1, 0], 1, p=[probs, 1-probs])