0

I have an array that looks like this:

array = numpy.array([[3,5,4,2,1,6,8],[23,44,52,1,23,22,58]])

How do I sort the first row and have it change the result of the second row as well? This is what I mean:

new_array = [[1,2,3,4,5,6,8],[23,1,23,52,44,22,58]]
1

1 Answer 1

1

You can use argsort, array[0].argsort() gives the indices that will sort the first row and then use the indices to reorder all columns:

array[:, array[0].argsort()]
array([[ 1,  2,  3,  4,  5,  6,  8],
       [23,  1, 23, 52, 44, 22, 58]])
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.