Home > Mobile >  Order sorting of an ndarray by indexes in python?
Order sorting of an ndarray by indexes in python?

Time:02-23

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

CodePudding user response:

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

  • Related