借助matrix.sum()方法,我们可以使用相同的方法找到矩阵中的值之和。
用法:matrix.sum()
返回:Return sum of values in a matrix
范例1:
在此示例中,我们可以通过使用以下公式找到矩阵中的值之和matrix.sum()方法。
# import the important module in python 
import numpy as np 
             
# make matrix with numpy 
gfg = np.matrix('[4, 1; 12, 3]') 
             
# applying matrix.sum() method 
geek = gfg.sum() 
   
print(geek)
输出:
20
范例2:
# import the important module in python 
import numpy as np 
             
# make matrix with numpy 
gfg = np.matrix('[4, 1, 9; 12, 3, 1; 4, 5, 6]') 
             
# applying matrix.sum() method 
geek = gfg.sum(axis = 1) 
   
print(geek)
输出:
[[14] [16] [15]]
相关用法
- Python Numpy numpy.ndarray.__divmod__()用法及代码示例
 - Python Numpy numpy.ndarray.__invert__()用法及代码示例
 - Python Numpy numpy.ndarray.__mod__()用法及代码示例
 - Python Numpy numpy.ndarray.__floordiv__()用法及代码示例
 - Python Numpy numpy.ndarray.__add__()用法及代码示例
 - Python Numpy numpy.ndarray.__sub__()用法及代码示例
 - Python Numpy numpy.ndarray.__mul__()用法及代码示例
 - Python Numpy numpy.ndarray.__pow__()用法及代码示例
 - Python Numpy numpy.ndarray.__or__()用法及代码示例
 - Python Numpy numpy.ndarray.__and__()用法及代码示例
 - Python Numpy numpy.ndarray.__xor__()用法及代码示例
 - Python Numpy numpy.ndarray.__iadd__()用法及代码示例
 - Python Numpy numpy.ndarray.__isub__()用法及代码示例
 - Python Numpy numpy.ndarray.__imul__()用法及代码示例
 - Python Numpy numpy.ndarray.__ne__()用法及代码示例
 
注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 Python | Numpy matrix.sum()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
