1

I have an array like this:

[[0, 46.0], [1, 83.0], [2, 111.0], [3, 18.0], [4, 37.0], [5, 55.0], [6, 0.0], [7, 9.0], [8, 9.0]]

I want to return the array where the second element is the highest. In this example: [2, 111]

How can I do that?

Until now I have tried numpy.amax(array, axis=0) and numpy.amax(array, axis=1). But they do not consider my condition, that I just want to consider the last element per array.

3
  • max(my_list, key=lambda x: x[1]) ? Commented Dec 22, 2020 at 18:08
  • Does this answer your question? find row or column containing maximum value in numpy array Commented Dec 22, 2020 at 18:18
  • 1
    @Asocia your solution works fine for me. In the answer section s.o. gave the same answer. As your answer came sooner I would recognize your answer as solution if you would post it in the answer section. Commented Dec 22, 2020 at 18:41

2 Answers 2

0

You could use max with a key argument:

result = max(arr, key = lambda x : x[1])
Sign up to request clarification or add additional context in comments.

Comments

0

If you array is an numpy array, you can use np.argmax to get the index and slice:

a[np.argmax(a[:,1])]
# array([  2., 111.])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.