I have a Numpy 3d array with 0 and 1 values, something like this:
array([[[ 1, 1, 0, 1],
[ 0, 0, 1, 1]],
[[ 1, 1, 1, 1],
[ 0, 1, 0, 1]]])
I would like to "add" (+ operation) each value in a "line" of the array following a specific condition: If I have consecutive "1" values, I put the sum. If I have 0, I keep it as it is. After a "0" values I restart counting.
The output that I would like to get is:
array([[[ 2, 0, 1],
[ 0, 0, 2]],
[[ 4],
[ 0, 1, 0, 1]]])
The output may be "lines" with different sizes. Can I still do it with numpy? I searched on the forums, numpy tools, but I didn't find anything regarding my specific problem. If someone could point me towards the proper documentation/tool I would appreciate it. Thank you.