Even though I strongly suggest NumPy (see comment below the question of OP), this one is without NumPy (only uses the built-in function enumerate
and also works for ragged arrays):
dist = [[ 0.0,
1804.04,
2120.09,
5502.24],
[ 1804.04,
0.0,
7395.44,
5828.17]] # list of lists
maximum, max_line, max_col = 0, 0, 0 # !!!
for line, l in enumerate(dist):
for col, c in enumerate(l):
if c > maximum: maximum, max_line, max_col = c, line, col
print(maximum, max_line, max_col)
In the line marked with !!!
it is assumed that only positive values are in your matrix dist
(which from the name dist
and its symmetry in the unedited post of OP, as well as the zero-elements on the diagonal I assumed to be plausible). Otherwise one would have to choose a smaller starting value for maximum
.
Here's how it would work with NumPy (see np.argmax
and np.unravel_index
):
import numpy as np
dist = np.array(dist) # array
print(np.unravel_index(np.argmax(dist), dist.shape))