0

I would like to determine the running sum of true values, but reset to zero when an element is false.

For example, the input:

np.array([0,0,1,1,1,1,0,0,0,1,0,1,0,0,1,1])

would result in:

np.array([0,0,1,2,3,4,0,0,0,1,0,1,0,0,1,2])

I prefer a pure numpy solution

user2133814
  • 2,431
  • 1
  • 24
  • 34
  • 1
    Your example works directly with the linked answer; you could replace `(a == 1)` with `(a != 0)` to support all truelike values. – DSM Dec 17 '15 at 21:28
  • @DSM Sorry for the duplicate. I didn't find that question when I searched. Thank you for the response – user2133814 Dec 17 '15 at 22:39

0 Answers0