numpy.sum

numpy.sum(aaxis=Nonedtype=Noneout=Nonekeepdims=False)[source]

Sum of array elements over a given axis.

Parameters:

a : array_like

Elements to sum.

axis : None or int or tuple of ints, optional

Axis or axes along which a sum is performed. The default (axis = None) is perform a sum over all the dimensions of the input array. axis may be negative, in which case it counts from the last to the first axis.

New in version 1.7.0.

If this is a tuple of ints, a sum is performed on multiple axes, instead of a single axis or all the axes as before.

dtype : dtype, optional

The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of a is used. An exception is when a has an integer type with less precision than the default platform integer. In that case, the default platform integer is used instead.

out : ndarray, optional

Array into which the output is placed. By default, a new array is created. If out is given, it must be of the appropriate shape (the shape of a with axis removed, i.e., numpy.delete(a.shape, axis)). Its type is preserved. See doc.ufuncs (Section “Output arguments”) for more details.

keepdims : bool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original arr.

Returns:

sum_along_axis : ndarray

An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned. If an output array is specified, a reference to out is returned.

See also

ndarray.sum
Equivalent method.
cumsum
Cumulative sum of array elements.
trapz
Integration of array values using the composite trapezoidal rule.

meanaverage

Notes

Arithmetic is modular when using integer types, and no error is raised on overflow.

Examples

>>>

>>> np.sum([0.5, 1.5])
2.0
>>> np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32)
1
>>> np.sum([[0, 1], [0, 5]])
6
>>> np.sum([[0, 1], [0, 5]], axis=0) #axis=0是按列求和
array([0, 6])
>>> np.sum([[0, 1], [0, 5]], axis=1) #axis=1 是按行求和
array([1, 5])

If the accumulator is too small, overflow occurs:

>>>

>>> np.ones(128, dtype=np.int8).sum(dtype=np.int8)
-128

python numpy sum函数用法的更多相关文章

  1. python numpy argsort函数用法

    numpy.argsort numpy.argsort(a, axis=-1, kind='quicksort', order=None)[source] Returns the indices th ...

  2. Python Numpy shape 基础用法(转自他人的博客,如涉及到侵权,请联系我)

    Python Numpy shape 基础用法 shape函数是numpy.core.fromnumeric中的函数,它的功能是读取矩阵的长度,比如shape[0]就是读取矩阵第一维度的长度.它的输入 ...

  3. 细说Python的lambda函数用法,建议收藏

    细说Python的lambda函数用法,建议收藏 在Python中有两种函数,一种是def定义的函数,另一种是lambda函数,也就是大家常说的匿名函数.今天我就和大家聊聊lambda函数,在Pyth ...

  4. 【313】python 中 print 函数用法总结

    参考:python 中 print 函数用法总结 参考:Python print() 函数(菜鸟教程) 参考:Python 3 print 函数用法总结 目录: 字符串和数值类型 变量 格式化输出 p ...

  5. Python 3 print 函数用法总结

    Python 3 print 函数用法总结 1. 输出字符串和数字 print("runoob")    # 输出字符串 runoob print(100)            ...

  6. python format格式化函数用法

    python format格式化函数用法 原文 Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前 ...

  7. python中numpy.sum()函数

    讲解清晰,转载自:https://blog.csdn.net/rifengxxc/article/details/75008427 众所周知,sum不传参的时候,是所有元素的总和.这里就不说了. 1 ...

  8. Numpy常用函数用法大全

    .ndim :维度.shape :各维度的尺度 (2,5).size :元素的个数 10.dtype :元素的类型 dtype(‘int32’).itemsize :每个元素的大小,以字节为单位 ,每 ...

  9. Python的range()函数用法

    Python的range()函数有三种用法,简单地说就是下图的三种用法: 运行结果如下:

随机推荐

  1. mysql之视图

    视图      视图是虚拟的表.与包含数据的表不一样,视图只包含使用时动态检索数据的查询. 理解视图最好的办法就是来看一下例子: SELECT cust_name , cust_contact FRO ...

  2. mysql之select(二)

    union 联合 作用: 把2次或多次查询结果合并起来. 要求:两次查询的列数一致.推荐:查询的每一列,相对应得列类型也一样. 可以来自于多张表.多次sql语句取出的列名可以不一致,此时,以第1个sq ...

  3. 绑定CPU

    处理器的亲和性 软亲和性(affinity) 意味着进程并不会在处理器之间频繁迁移,而 硬亲和性(affinity) 则意味着进程需要在您指定的处理器上运行. 通常 Linux 内核都可以很好地对进程 ...

  4. Zabbix监控解决方案

    思通运维监控主要用来监控IT 基础设施组件的可用性和性能.监控项目是不受限制的,并且可以对IT 基础设施健康状态进行复杂分析.通过确定IT 系统问题的“来源”,使用户快速响应故障来降低宕机成本. 网络 ...

  5. 安装MySQldb出错解决方法

    sudo yum install mysql-devel sudo yum install python-devel _mysql.c:36:23: error: my_config.h: No su ...

  6. 谈谈MVC模式

    谈谈MVC模式   作者: 阮一峰 1. 如何设计一个程序的结构,这是一门专门的学问,叫做"架构模式"(architectural pattern),属于编程的方法论. MVC模式 ...

  7. How to configure Spring facet in IntelliJ IDEA

    遇到了这个问题,稀里糊涂的就给搞定了,在stackoverfolw上看到了相同的问题,直接拷贝下来吧 Spring Configuration Check Unmapped Spring config ...

  8. iOS:地图:MapKit和CoreLocation

    地图:MapKit和CoreLocation 简介: 现在很多的社交软件都引入了地图和定位功能,要想实现这2大功能,那就不得不学习其中的2个框架:MaKit和CoreLocation CoreLoca ...

  9. Netty4.x中文教程系列(二) Hello World !

    在中国程序界.我们都是学着Hello World !慢慢成长起来的.逐渐从一无所知到熟悉精通的. 第二章就从Hello World 开始讲述Netty的中文教程. 首先创建一个Java项目.引入一个N ...

  10. 着色器(Shader)

    着色器(Shader) 顶点着色器(Vertex shader) 片段着色器(Fragment shader) 几何着色器(Geometry Shader) 提供通用计算能力的着色器(Compute ...