+ 1

If this is my matrix how to print the sum of each column?

m=[1,2,3] n=[4,5,6]

11th Oct 2018, 3:35 PM
Pranay Bhoir.
Pranay Bhoir. - avatar
4 Answers
+ 3
you can do this with the help of numpy module it's all about matrix.you can do everything with your matrix with the help of numpy module check out these lessons from solelearn. https://www.sololearn.com/learn/6671/?ref=app check this lesson for sum of columns. https://www.sololearn.com/learn/6685/?ref=app
11th Oct 2018, 3:50 PM
Maninder $ingh
Maninder $ingh - avatar
+ 2
m = [[1, 2, 3], [4, 5, 6]] mT = list(zip(*m)) print([sum(column) for column in mT]) #First take a transpose and then output sum
11th Oct 2018, 4:50 PM
Yash✳️
Yash✳️ - avatar
+ 2
Pranay Bhoir. You can save the sums in a variable and then access single elements.. Like sums[0] or sums[1] OR, check out the str.join function
12th Oct 2018, 1:22 AM
Yash✳️
Yash✳️ - avatar
+ 1
yash how to print sum without showing it in list brackets?
11th Oct 2018, 6:42 PM
Pranay Bhoir.
Pranay Bhoir. - avatar