The function a[a.size - (a >= 0)[::-1].argmax():] = 0 assigns 0 to the arrays if the array is equal to or less than 0, it also assigns 0 to the arrays that are behind it. In example a the function works fine it assigns 0 to third element till the last element. However in example b it does not do that even though the initial value is negative. How could i modify the function so that it gives me the desired result.
Example A
a = np.array([[ 123.7 131.1 -4578.2 -4579.1 -4520.1 -4561.3 -4490.9 -4498.5 -4513.8
-4550.9]])
a[a.size - (a >= 0)[::-1].argmax():] = 0
Output = [123.7 131.1 0. 0. 0. 0. 0. 0. 0. 0. ]
Example B
b = np.array([-570., -593.37, -286.59771, -264.24308862])
b[b.size - (b >= 0)[::-1].argmax():] = 0
Output = [-570., -593.37, -286.59771, -264.24308862]
Desired Output = [0, 0, 0, 0]