Given a grid of numbers like
g=[[2, 2, 2, 3, 2],
[2, -1, -1, 3, 3],
[3, 2, -1, 3, 3],
[2, 4, 3, 3, 3],
[-1, 2, 2, -1, 1]]
i am searching for the maximum value in that 2d list, which, in this example, is obivously 4.
To find that, max(max(graph,key=max)) does the job (even though i know it calls max for the line with the maximum value twice, so it is not perfectly efficient)
But that is only half what i am looking for. I need the coordinates of this 4. I would like to have a short, efficient and pythonic piece of code like
x, y = find_2d_max_index(g) that gives me the position of the max number, without doing the triple max thing before. I want to avoid to use the index() method after finding the max as that would be very inefficient.
I looked into numpy argmax, but could not get it to work in this application with a 2d list.
Any help is appreciated.