Looking for an efficient solution that performs a cumulative sum that reset on zeros.
For example:
3×3 Matrix{Float64}:
1.0 2.0 3.0
0.0 5.0 6.0
10.0 0.0 9.0
the desired output is
3×3 Matrix{Float64}:
1.0 2.0 3.0
0.0 7.0 9.0
10.0 0.0 18.0
cumsum()
exists but doesn't reset on zeros:
julia> cumsum(a, dims=1)
3×3 Matrix{Float64}:
1.0 2.0 3.0
1.0 7.0 9.0
11.0 7.0 18.0
I have seen a lot of answers to this question in Python and R. I am looking for a solution in Julia, thank you.