You can use numpy.cumprod
:
>>> np.cumprod(arr)
array([ 1, 2, 6, 24, 120, 720, 5040,
40320, 362880, 3628800], dtype=int32)
Just in case you don't want to use numpy and you would rather stay in pure python (perhaps because you want pythons unlimited precision integers and don't care too much about speed) you could also use itertools.accumulate
:
>>> import itertools
>>> import operator
>>> list(itertools.accumulate(arr, operator.mul))
[1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800]
Note: The itertools.accumulate
function requires python3.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…