累加列表元素,同时每次累加一个常量

Accumulate list elements while adding a constant to each accumulation

我正在使用 np.cumsum():

在列表中累积值,以便一个值是所有先前值的总和
l=[4,2,1,3]
c = np.cumsum(l)
print(c)

[4 6 7 10]

但我还想将 1 添加到每个计算中,以便结果如下所示:

[4 7 9 13]

实现该目标的最简单方法是什么?

给你:

res = c + np.arange(len(c))