You can try cumsum from theano: from theano.tensor.extra_ops import cumsum
from theano.tensor.extra_ops import cumsum