Maximum Column And Row Sum Of Matrix In Python
I take an input of a matrix import numpy as np l = np.array([input().split() for _ in range(3)], dtype=np.int) 1 2 3 4 5 6 7 8 9 Now I want to display the largest sum. It can be
Solution 1:
A working example:
import numpy as np
x = np.array([[1,2,3],[4,5,6],[7,8,9]]);
rowSum = np.sum(x, axis=1)
colSum = np.sum(x, axis=0)
print("row {} {}".format(np.argmax(rowSum)+1, np.max(rowSum)))
print("col {} {}".format(np.argmax(colSum)+1, np.max(colSum)))
# output:# row 3 24# col 3 18
See
Post a Comment for "Maximum Column And Row Sum Of Matrix In Python"