Python之学习所遇

来源:互联网 发布:nginx mail模块 编辑:程序博客网 时间:2024/04/29 10:32

1、np.mean 与 np.average 之区别:

 np.mean always computes an arithmetic mean, and has some additional options for input and output (e.g. what datatypes to use, where to place the result).

>>> a = np.array([[1, 2], [3, 4]])>>> np.mean(a)2.5>>> np.mean(a, axis=0)array([ 2.,  3.])>>> np.mean(a, axis=1)array([ 1.5,  3.5])

np.average can compute a weighted average if the weights parameter is supplied.

可以用来求带权重的均值 

>>> dataarray([[0, 1],       [2, 3],       [4, 5]])>>> np.average(data, axis=1, weights=[1./4, 3./4])array([ 0.75,  2.75,  4.75]
1 0