Monte Carlo Sim的求和结果; Python
在 python 2.7 中工作。
我有一个参数,它采用一个列表,将参数列表的值添加到列表“team”中,然后比较某些位置值并根据值返回胜利、失败或平局。
def starterTrans3(starter):
wins = 0
losses = 0
nd = 0
team = [[1, 0], [1, 0], [0, 5], [3, -1]]
random.shuffle(team)
for t, s in zip(team, starter):
t.extend(s)
score_add(team, exit_score(team, starter))
length = len(starter)
for i in range(0, length):
if team[i][4] > 0 and (team[i][1] > -team[i][4]) and team[i][2] >= 5:
wins += 1
elif team[i][4] < 0 and (team[i][1] <= -team[i][4]):
losses += 1
elif (team[i][4] <= 0 and team[i][1] >= -team[i][4]):
nd += 1
return wins, losses, nd
我希望能够多次模拟结果,使用 random.shuffle(team) 对团队列表进行随机排序。
我可以使用以下方法来做到这一点:
def MonteCarlo(starter, x):
for i in range(0, x):
print starterTrans3(starter)
但我希望能够将所有模拟中的所有胜利、失败和平局相加,然后除以模拟次数(在本例中为 x),以获得平均胜利,所有模拟中的损失和联系。
我尝试更改 starterTrans 函数以使其有一个等于 += wins 的total_wins 变量,但我一直无法弄清楚。有什么想法吗?
Working in python 2.7.
I have an argument that takes a list, adds the values of the argument list to the list "team", and then compares certain positional values and returns win, loss, or tie depending upon the values.
def starterTrans3(starter):
wins = 0
losses = 0
nd = 0
team = [[1, 0], [1, 0], [0, 5], [3, -1]]
random.shuffle(team)
for t, s in zip(team, starter):
t.extend(s)
score_add(team, exit_score(team, starter))
length = len(starter)
for i in range(0, length):
if team[i][4] > 0 and (team[i][1] > -team[i][4]) and team[i][2] >= 5:
wins += 1
elif team[i][4] < 0 and (team[i][1] <= -team[i][4]):
losses += 1
elif (team[i][4] <= 0 and team[i][1] >= -team[i][4]):
nd += 1
return wins, losses, nd
I want to be able to simulate the results many times, using random.shuffle(team) to randomly order the team list.
I can do that using:
def MonteCarlo(starter, x):
for i in range(0, x):
print starterTrans3(starter)
But I would like to be able to sum all of the wins, losses and ties from all the simulations, and then divide by the number of simulations (in this case x), to get an average of wins, losses, and ties in all of the simulations.
I've tried changing the starterTrans function to have a total_wins variable that is equal to += wins, but I haven't been able to figure it out. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能不明白你的意思,但是......
或者
i may not getting your point, but...
or