I have a numeric series like [0,0,0,0,1,1,1,0,0,1,1,0]. I would like to calculate the numeric sum from the last non-zero values. i.e the cumsum will be reset to zero once a zero entry occurs. input: [0,0,0,0,1,1,1,0,0,1,1,0] output:[0,0,0,0,1,2,3,0,0,1,2,0] Is there a built-in python function able to achieve this? Or better way to calculate it without loop? Continue reading...