📜  Python| numpy matrix.sum()

📅  最后修改于: 2022-05-13 01:54:24.353000             🧑  作者: Mango

Python| numpy matrix.sum()

matrix.sum()方法的帮助下,我们可以使用相同的方法找到矩阵中值的总和。

示例 #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]]