I am trying to understand the mechanism of a function around a sorting topic in numpy.
import numpy as np
arr = [[8, 5, 9],
[3, 9.5, 5], [5.5, 4, 3.5], [6, 2, 1],
[6,1,2],[3,2,1],[8,5,3]]
res = sorted(arr, key=np.argmax)
This gives me the following result:
print(res)
[[5.5, 4, 3.5], [6, 2, 1], [6, 1, 2],
[3, 2, 1], [8, 5, 3], [3, 9.5, 5], [8, 5, 9]]
I am an R user and not very familiar with Python. I may have some idea of the role of the key argument, but for this example, I ask you for help. In the simple case, if the argument keyis defined as a function that returns the first element, it sortedsorts the array based on its first element, but I do not see how this works with argmax. Thank,