I have a list of probabilities p = [p1, p2, …, pn].
All I want is to simulate a list s = [0, 1, 0, 0, 1, …, 1], whose first element is 0 with probability p1 and 1 with probability 1 - p1, and then so on for the next elements, always matching the corresponding probabilities in the p-list.
Currently my solution is to for-loop over p, and then append to s the output from np.random.choice() called on each individual pn.
s = []
for item in p:
s.append(np.random.choice([0, 1], p=[item, 1 - item]))