Skip to content

Commit 5c76544

Browse files
committed
pytyhon matrix sum
1 parent 5d63cf3 commit 5c76544

File tree

1 file changed

+3
-0
lines changed
  • docs/19_python内置常用算法和数据结构

1 file changed

+3
-0
lines changed

docs/19_python内置常用算法和数据结构/builtins.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ issorted = all(l[i] <= l[i+1] for i in range(len(l) - 1))
122122
# python3 一行代码求前缀和
123123
from itertools import accumulate
124124
presums = list(accumulate([1,2,3])) # [1, 3, 6]
125+
126+
# 一行代码求矩阵和 https://stackoverflow.com/questions/10713150/how-to-sum-a-2d-array-in-python
127+
allsum = sum(map(sum, matrix)) # 或者 allsum = sum((sum(row) for row in matrix))
125128
```
126129

127130
# 链表题目调试函数

0 commit comments

Comments
 (0)