The problem I have is as follows
I have a 1-D list of integers (or np.array) with 3 values
l = [0,1,2]
I have a 2-D list of probabilities (for simplicity, we'll use two rows)
P =
[[0.8, 0.1, 0.1],
[0.3, 0.3, 0.4]]
What I want is numpy.random.choice(a=l, p=P)
, where each row in P (probability distribution) is applied to l. So, I want a random sample to be drawn from [0,1,2] with prob. dist. [0.8, 0.1, 0.1] first, then with prob. dist. [0.3, 0.3, 0.4] next, to give me two outputs.
===== Update ======
I can use for loops or list comprehension, but I am looking for a fast/vectorized solution.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…