python 怎么算矩阵每列的和
例子:mat=[[1,2,3],[10,20,30],[100,200,300]]list_sums_cols=addValuesInAllCols(mat)print(...
例子:
mat = [ [1,2,3], [10,20,30], [100,200,300] ]
list_sums_cols = addValuesInAllCols(mat)
print (list_sums_cols)
should produce the output:[111, 222, 333] 展开
mat = [ [1,2,3], [10,20,30], [100,200,300] ]
list_sums_cols = addValuesInAllCols(mat)
print (list_sums_cols)
should produce the output:[111, 222, 333] 展开
1个回答
展开全部
output = []
nrow = len(mat)
ncol = len(mat[0])
for i in range(ncol):
output.append(sum([mat[x][i] for x in range(nrow)]))
print output
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询