Sorry about the title, I would be looking for a suggestion if someone has a better description. I want a function (that is as quick as possible) that gets the non-zero entries and populates a new array with the ordered version of the previous array. It probably is clearer from the example below:
Input Array
np.random.seed(2)
a = np.random.randint(0,10,10)
b = np.random.randint(0,10,10)
c = np.random.randint(0,10,10)
a = 0 * (a % 2) + (1-(a % 2))*a
b = 0 * (b % 2) + (1-(b % 2))*b
c = 0 * (c % 2) + (1-(c % 2))*c
arr = np.array([a,b,c])
arr
>>> array([[8, 8, 6, 2, 8, 0, 2, 0, 0, 4],
[4, 0, 0, 0, 6, 4, 0, 0, 6, 0],
[0, 0, 8, 4, 6, 0, 0, 2, 0, 4]])
Output Array
outArr = np.empty_like(arr)
outArr[0,:] = (arr[0,:] > 0) * arr[0,:] + ~(arr[0,:] > 0) * (arr[1,:] > 0) * arr[1,:] + ~(arr[0,:] > 0) * ~(arr[1,:] > 0) * arr[2,:]
outArr[1,:] = (arr[0,:] > 0) * arr[1,:] + (arr[0,:] > 0) * ~(arr[1,:] > 0) * arr[2,:]
outArr[2,:] = (arr[0,:] > 0) * (arr[1,:] > 0) * arr[2,:]
outArr
>>> array([[8, 8, 6, 2, 8, 4, 2, 2, 6, 4],
[4, 0, 8, 4, 6, 0, 0, 0, 0, 4],
[0, 0, 0, 0, 6, 0, 0, 0, 0, 0]])
Where I have hard coded this array to be 3 rows only so I can hand type the function, in reality this could be more rows (on the order of tens nothing too crazy).
EDIT:
The dimensions that I would actually like to use are 5ish rows by 100-150k columns
The data type will always be integers
Finally, the update process is I add a new row at the bottom, justify upwards, and then remove all trailing rows of only 0s (null values)