我有大量的列表,我想计算平均值而不存储所有列表。有没有python实现呢?
由于
答案 0 :(得分:1)
如果你想平均整个数组(必须是兼容的形状):
running_sum = None
count = 0
for a in yourarraysource:
if running_sum is None:
running_sum = a
else:
running_sum = running_sum + a
count += 1
average = running_sum / count
如果你想平均所有元素:
running_sum = 0
count = 0
for a in yourarraysource:
running_sum += a.sum()
count += a.size
average = running_sum / count