numpy.sum函数

来源:互联网 发布:于丹 知乎 编辑:程序博客网 时间:2024/05/29 03:58

numpy.sum函数

numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)

numpy.sum用于计算矩阵的和,axis=1时按行计算,axis=0时按列计算

>>> from numpy import *>>> rmat = mat(random.rand(3,3))>>> rmatmatrix([[ 0.47309329,  0.08030614,  0.35519215],        [ 0.90260887,  0.92735268,  0.9698393 ],        [ 0.42469663,  0.57946614,  0.83821899]])>>> test = rmat.sum(axis=0)>>> testmatrix([[ 1.80039879,  1.58712496,  2.16325044]])>>> test = rmat.sum(axis=1)>>> testmatrix([[ 0.90859157],        [ 2.79980084],        [ 1.84238177]])
原创粉丝点击