我有一个稀疏矩阵,我需要在其中添加多行(以块为单位),比如说1:30,然后是45:50,等等。最有效的方法是什么?
wouldn't sum
do the job? try:
a = np.array([[1,1],
[2,2],
[3,3]])
>>> a[1:3]
array([[2, 2],
[3, 3]])
>>> sum(a[1:3])
10
Edit: if you are looking to sum 'vertically'
>>> sum( a, axis=0 )
array([6, 6])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.