1

how do I sort a ndarray based on one of its rows? example:

ndarray = [['a' 'b' 'c']
           ['2' '7' '6']
           ['3' '0' '1']]

I sort based on the second row and i have:

newsortedndarray = [['a' 'c' 'b']
                    ['2' '6' '7']
                    ['3' '1' '0']]

please help

2 Answers 2

3

Use argsort function to get an order of "columns".

ndarray[:,np.argsort(ndarray[1,:])]
Sign up to request clarification or add additional context in comments.

Comments

0

Alternatively, you can np.transpose() your array to make the former columns your new rows.

1 Comment

but wouldnt that just give me: python [['a' '2' '3'] ['b' '7' '0'] ['c' '6' '1']]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.