题解 | 多组_二维数组_T组形式
多组_二维数组_T组形式
https://www.nowcoder.com/practice/fe1e902e076b46dd82e7d42e12617893
# 接收数据组数t
t = int(input().strip())
for _ in range(t):
# 接收矩阵的行列值
a = list(map(int, input().split()))
row,col = a[0],a[1]
ans = 0
for _ in range(row):
row_val = list(map(int,input().split()))
ans = ans+sum(row_val)
print(ans)
二维数组的元素求和实际上就是拆解成row(行数)个一维数组求和
python可以使用sum(row_val)来方便的对一维数组进行求和