在while循环内计算平均值

时间:2021-04-02 20:52:28

标签: python pandas loops while-loop mean

所以我有这个代码:

def run_simulation(nba = 100, maxIter = 10, probI = 0.2, probR = 0.2, probI_init = 0.1, network = nx.erdos_renyi_graph, netParam=0.1, rep=10):
r = 0
while r < rep:
    init(nba, probI)
    i = 0
    while i < maxIter:
        step(probR, probI)
        nbI = collect_statistics()
        if nbI == 0:
            break
        i = i + 1
    print(statS[-1])
    r = r +1

run_simulation()

这段代码产生 10 个这样的数字:

Python code

我的问题是:有没有办法计算这 10 个数字的平均值?

非常感谢!

1 个答案:

答案 0 :(得分:1)

由于 Const 显然是在此例程之外创建和修改的全局列表,所以有点难以判断,但显而易见的答案是在循环退出后 statS