-2

m,n) shaped numpy array. I would like to sort the whole array by the values in the index [1,2,:] say. Is there an easy way to do this? I tried to use pandas Panel but for whatever reason there is no sort by values function for it.

That 'duplicate' someone linked only seems to work for a column in an 2d array. I am using the term column in a more general sense i.e a 1d sub-array of an (mxnxlx..) array

2
  • 1
    Possible duplicate of How to sort multidimensional array by column? Commented Aug 22, 2016 at 18:05
  • Use argsort on the selected row/column, and then order the array with that index. Commented Aug 22, 2016 at 18:39

1 Answer 1

0

So how I did it was using argsort as hpaulj said, given a array arr that was (m,n,l) dimension and a column indexed by (i,j,:).

sorted = np.empty(arr.shape):
for k in range(arr.shape[2]):
    sorted[:,:,i] = arr[:,:,np.argsort(arr[i,j,:])[i]]
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.