输出100次1,2,3,4的值,其中1出现的概率为 ,2出现的概率为 ,3出现的概率为 ,4出现的概率为
import numpy as np
np.random.seed(0)
p = np.array([0.1, 0.0, 0.7, 0.2])
for i in range(100):
index = np.random.choice([1, 2, 3, 4], p=p.ravel())
print(index)
3
3
3
3
3
3
3
4
4
3
3
3
3
4
1
1
1
4
3
4
4
3
3
3
3
3
3
4
3
3
3
3
3
3
1
3
3
3
4
3
3
3
3
1
3
3
3
3
3
3
3
3
4
3
3
3
3
3
3
3
3
3
3
3
3
3
4
1
4
1
4
3
4
3
3
1
3
3
3
3
3
3
1
3
3
3
3
1
3
4
3
3
3
3
3
3
3
1
4
1