Choose list variable given probability of each variable

后端 未结 5 1444
野趣味
野趣味 2020-12-08 00:34

I\'ve been trying to code a program that uses the softmax activation function in the middle.

Right now, I have a list of probabilities like this:

P[0         


        
5条回答
  •  旧时难觅i
    2020-12-08 01:21

    import random
    
    probs = [0.1, 0.25, 0.6, 0.05]
    r = random.random()
    index = 0
    while(r >= 0 and index < len(probs)):
      r -= probs[index]
      index += 1
    print index - 1
    

提交回复
热议问题