If I have an numpy array like the one below, how can I right justify or left justify the elements tat are greater than zero
[[ 0. 5. 0. 2.] [ 0. 0. 3.
With the assumptions that every row contains at least one zero, and no negatives, this is just a partition:
>>> np.partition(x, 1) array([[ 0., 0., 5., 2.], [ 0., 0., 3., 2.], [ 0., 0., 0., 0.], [ 0., 0., 2., 1.]])
Edit: This shuffles the rows, so is little better than a sort