天天看点

python累加的几种方法

# 使用Python自带工具
from itertools import accumulate

res = accumulate(range(10))
print(list(res))

# 使用numpy
import numpy as np

r=np.cumsum(np.array(range(10)))
print(list(r))
           
安利一门Python超级好课! 扫码下单输优惠码【csdnfxzs】再减5元,比官网还便宜!
python累加的几种方法