numpy中mean跟average区别

96
阳光夜风
2017.07.13 17:35* 字数 36

np.mean直接计算平均数
np.average计算加权平均数(如果有权重weight的话)

部分源码

np.mean:

try:
    mean = a.mean
except AttributeError:
    return _wrapit(a, 'mean', axis, dtype, out)
return mean(axis, dtype, out)

np.average:

if weights is None :
    avg = a.mean(axis)
    scl = avg.dtype.type(a.size/avg.size)
else:
    #code that does weighted mean here

if returned: #returned is another optional argument
    scl = np.multiply(avg, 0) + scl
    return avg, scl
else:
    return avg
机器学习
Web note ad 1