Anton
Anton

Reputation: 390

Order sorting of an ndarray by indexes in python?

want to sort np.ndarray indexes of an array such as

[[.5,.7, .9], [.6, .0, .8]]

result would look like this

[[1,1],[0,1],[1,0],[0,1],[1,2],[0,3]]

applying those indexes will get correct sorting order and at same time can be applied to other structures that match the data.

I tried np.argsort, but that doesn't give indexes for ndarray

Upvotes: 0

Views: 52

Answers (1)

Carlos Horn
Carlos Horn

Reputation: 1293

You can use np.argsort on the flat array and then use np.divmod to get the indexes of your previous shape. Edit: np.unravel_index is the divmod alternative for higher dimensions, see https://numpy.org/doc/stable/reference/generated/numpy.unravel_index.html

Upvotes: 1

Related Questions