Count since last occurence in NumPy
Split the array based on the condition and use the lengths of the remaining pieces and the condition state of the first and last element in the array.
Seemingly straightforward problem: I want to create an array that gives the count since the last occurence of a given condition.  In this condition, let the condition be that a > 0:
in:  [0, 0, 5, 0, 0, 2, 1, 0, 0]
out: [0, 0, 0, 1, 2, 0, 0, 1, 2]
I assume step one would be something like np.cumsum(a > 0), but not sure where to go from there.
Edit: Should clarify that I want to do this without iteration.