1

In Numpy, how do I create an array of indices which can be used return the values of the source array in sorted order? eg:

Source: [[4 2 6 7] [1 4 8 9] [3 1 0 3]] Indices: [10 4 9 1 8 11 0 5 2 3 6 7] 

2 Answers 2

2

Take a look at numpy.argsort - it will return the indices that would sort your array. You can also specifiy the axis along which to sort. Try:

a = numpy.asarray([[4, 2, 6, 7], [1, 4, 8, 9], [3, 1, 0, 3]]) numpy.argsort(a.flat) >> array([10, 4, 9, 1, 8, 11, 0, 5, 2, 3, 6, 7]) 
Sign up to request clarification or add additional context in comments.

Comments

0

The answer's in the manual:

src = [[ ... ]] ravel_src = np.ravel(src) indices = np.argsort(ra) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.