Python program to Get the Rows and Columns with Maximum Sum of Elements

from random import random
matrix = []
for i in range(6):
 row = []
 for j in range(6):
    row.append(int(random()*10))
 matrix.append(row)
for row in matrix:
 print(row)
rmaxi = 0
rid = 0
i = 0
for row in matrix:
 if sum(row) > rmaxi:
    rmaxi = sum(row)
    rid = i
 i += 1
print('Row ID:',rid, '=', rmaxi)
cmaxi = 0
cid = 0
for i in range(6):
 sumcol = 0
 for j in range(6):
    sumcol += matrix[j][i]
 if sumcol > cmaxi:
    cmaxi = sumcol
    cid = i
print('Column ID:',cid, '=', cmaxi)

 

 

 

Output:

 [0, 2, 6, 8, 1, 9]
[4, 7, 3, 8, 3, 4]
[7, 9, 5, 7, 4, 4]
[5, 0, 4, 3, 6, 2]
[2, 6, 5, 5, 6, 8]
[9, 4, 8, 5, 5, 2]
Row ID: 2 = 36
Column ID: 3 = 36

 

Subscribe For Daily Updates

100+ Python Pattern Examplespython pattern examples - star patterns, number patterns