compute mean in python for a generator

后端 未结 10 2179
遇见更好的自我
遇见更好的自我 2021-01-01 21:58

I\'m doing some statistics work, I have a (large) collection of random numbers to compute the mean of, I\'d like to work with generators, because I just need to compute the

10条回答
  •  清酒与你
    2021-01-01 22:36

    If you know the length of the generator in advance and you want to avoid storing the full list in memory, you can use:

    reduce(np.add, generator)/length
    

提交回复
热议问题