Is this possible to accomplish with Numpy and with good performance?
Initial 2D array:
array([[0, 1, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 0],
[1, 0, 0, 0, 0, 1]])
If the sum of each row is less than 4, set the last item in each row to 1:
array([[0, 1, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 1],
[1, 0, 0, 0, 0, 1]])
Divide each item in each row with the sum of each row and get this result:
array([[0, 0.25, 0.25, 0.25, 0.25, 0],
[0, 0, 0.5, 0, 0, 0.5],
[0.5, 0, 0, 0, 0, 0.5]])