I have a numpy array in Python which is n-by-n (in the example is 3-by-3)and contains zero values in all the diagonal positions. e.g
array([[ 0. , -0.65 , 1.3 , 0.56],
[ 0.45 , 0. , 0.54, 43 ],
[ 0.5 , 0.12 , 0. , 7 ]
[ 0.2 , 0.3 , 0.4 , 0 ]])
Is it possible to sort the array without modifying the diagonal positions so as to look like the one below? Because all of the sorting functions will take into account the "zeros" that exist in the diagonal positions and will change their relative position.
array([[ 0. , 1.3 , 0.56 , -0.65],
[ 43 , 0. , 0.54 , 0.45 ],
[ 7 , 0.5 , 0. , 0.12 ]
[ 0.4 , 0.3 , 0.2 , 0 ]])
If the above operation cannot be done, then the N maximum values and their corresponding indexes in each row could suffice.
Till now i have tried sort and argsort but with no result.