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 in either columns or rows.
For example in this:
row 3 has maximum sum 24
So my output will be:
row 3 24
解决方案
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