0

I want to find indices in ascending order of elements in last row in a 2D numpy array. An example is as below.

ti = np.array([[255, 2, 255, 9], [4, 255, 6, 255], [23, 11, 5, 18]])

# output = function(ti[-1])
# output : 2, 1, 3, 0

How do I achieve this? np.argmin only gives one minimum, and I could not find any other way including using partition (which returns sorted elements instead). Kindly help.

6
  • 1
    I believe this is a duplicate of: stackoverflow.com/questions/22546180/… Commented Feb 20, 2019 at 17:58
  • What is "smaller" between [255, 2, 255, 9] and [4, 255, 6, 255]? How would you determine the "minimum"? Commented Feb 20, 2019 at 18:01
  • 2
    What does output 2, 1, 3, 0 denote exactly? Commented Feb 20, 2019 at 18:01
  • It's not at all clear what you're trying to do. You've got 4 numbers in the output, so you're not argsorting the rows. The numbers aren't right for argsorting the columns, or for taking the argmin of each column. I have no idea what that 2, 1, 3, 0 is supposed to be. Commented Feb 20, 2019 at 18:03
  • Are you trying to find the "nth minimum of a numpy array" as the title suggests or the " indices in ascending order" of all the elements as you wrote in the question? Commented Feb 20, 2019 at 18:09

1 Answer 1

0

I tried np.argsort which sort of gives this output. Others please englighten if any more insights to be added.

np.argsort(ti[-1])

output:

array([2, 1, 3, 0], dtype=int64)
Sign up to request clarification or add additional context in comments.

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.