When do batch means need different weights?

mean divides a sum by its observation count. Each batch contributes to the global mean in proportion to its size.

numpy.mean in practice

One batch has a single ten and another has three twos. Pooling gives four. Averaging batch means gives six because it weights both batches equally.

import numpy as np
np.mean([10,2,2,2])

Result 4.0

中文

不同长度的批次能直接平均批均值吗?

mean 将数值之和除以参与统计的元素数。跨批次汇总时,每批对总均值的贡献取决于其样本数。

numpy.mean 算例

一批只有一个 10,另一批有三个 2,总均值为 4。将两批均值各算一票会得到 6,相当于给两批相同权重。

import numpy as np
np.mean([10,2,2,2])

结果 4.0

References / 参考来源

Keep reading / 继续阅读