Suppose that we have a 2D numpy array and we use np.ma.masked_where to mask some elements. In each row, we want to move all the masked elements to the end while preserving the order of rest of the elements. Is there an easy loop-free way to do that?
For example, suppose we have the following masked 2D matrix:
a = [1, --, 2
4, 3, --
--, --,5]
We want to return:
a = [1, 2, --
4, 3, --
5,--, --]