numpy.average的用法
来源:互联网 发布:手机解锁软件 编辑:程序博客网 时间:2024/06/01 10:26
numpy.average
- numpy.average(a,axis=None, weights=None, returned=False)[source]
Compute the weighted average along the specified axis.
Parameters:
a : array_like
Array containing data to be averaged. If a is not an array, aconversion is attempted.
axis : int, optional
Axis along which to average a. If None, averaging is done overthe flattened array.
weights : array_like, optional
An array of weights associated with the values in a. Each value ina contributes to the average according to its associated weight.The weights array can either be 1-D (in which case its length must bethe size of a along the given axis) or of the same shape asa.If weights=None, then all data ina are assumed to have aweight equal to one.
returned : bool, optional
Default is False. If True, the tuple (average,sum_of_weights)is returned, otherwise only the average is returned.Ifweights=None, sum_of_weights is equivalent to the number ofelements over which the average is taken.
average, [sum_of_weights] : array_type or double
Return the average along the specified axis. When returned is True,return a tuple with the average as the first element and the sumof the weights as the second element. The return type isFloatif a is of integer type, otherwise it is of the same type asa.sum_of_weights is of the same type asaverage.
ZeroDivisionError
When all weights along axis are zero. See numpy.ma.average for aversion robust to this type of error.
TypeError
When the length of 1D weights is not the same as the shape ofaalong axis.
See also
mean
- ma.average
- average for masked arrays – useful if your data contains “missing” values
Examples
>>> data = range(1,5)>>> data[1, 2, 3, 4]>>> np.average(data)2.5>>> np.average(range(1,11), weights=range(10,0,-1))4.0
>>> data = np.arange(6).reshape((3,2))>>> dataarray([[0, 1], [2, 3], [4, 5]])>>> np.average(data, axis=1, weights=[1./4, 3./4])array([ 0.75, 2.75, 4.75])>>> np.average(data, weights=[1./4, 3./4])Traceback (most recent call last):...TypeError: Axis must be specified when shapes of a and weights differ.From:https://docs.scipy.org/doc/numpy/reference/generated/numpy.average.html
- numpy.average的用法
- numpy 矩阵的用法
- numpy nonzero的用法
- numpy tolist()的用法
- numpy的基础用法
- numpy的函数用法
- numpy的用法part1
- numpy.c_和numpy.squeeze的用法
- numpy.cov()和numpy.var()的用法
- SVM numpy sign的用法
- python之numpy的用法
- numpy中的nonzero()的用法
- numpy中的nonzero()的用法
- numpy中nonzero()的用法
- 记录numpy的一些用法
- numpy的用法(一)
- numpy的用法(二)
- numpy的一些简单用法
- 快速排序--学习笔记
- 我的web前端面试经历————百度
- 安卓动态注册广播
- SignalR + MVC5 简单示例
- 解决编译Apache出现的问题:configure: error: APR not found . Please read the documentation
- numpy.average的用法
- mysql基础(1)
- ButterKnife 使用方法
- C 中的typedef struct
- 多线程的创建
- 浅谈解析XML文件的跨浏览器实例
- HttpClient4.5 使用http连接池发送http请求深度示例
- Spring Web MVC学习笔记:原理简介与环境搭建
- jQuery插件扩展