【发布时间】:2015-01-25 06:52:25
【问题描述】:
事情就是这样。
我想以不同的概率生成两个值,1 和 -1。 当我运行这个脚本时,我收到消息“choice() got an unexpected keyword argument 'p'”
谁能告诉我为什么会发生这种情况以及如何解决它? 谢谢。
from scipy import *
import matplotlib.pyplot as plt
import random as r
def ruin_demo():
tmax = 1000 #The number of game rounds
Xi = 10 #The initial money the gambler has
T = []
M = []
t = 1
for N in linspace(0.3, 0.49, 100): #The probability changing region
meandeltaX = 1.0*N + (1-N)*(-1.0) #The expected value for each game round
M.append(meandeltaX)
while (t < tmax and Xi > 0):
deltaX = r.choice((1, -1), p=[N, 1-N]) # The change of money during each game round
#print deltaX
Xi = Xi + deltaX
t = t + 1
T.append(t)
plt.plot(M, T)
plt.show()
ruin_demo()
【问题讨论】:
标签: python python-2.7 random