import numpy as np nums = [1,3,4,7,5] preSum = np.cumsum(nums) print(preSum) 感觉这个就很方便了 [ 1 4 8 15 20]