willsonlincake 发表于 2022-4-8 18:48:43

NumPy np.cumsum累计求和的用法

>>> a =np.array([, ])
>>> a
array([,
       ])
>>> np.cumsum(a)
array([ 1,3,6, 10, 15, 21])
>>> np.cumsum(a, dtype=float)   # specifies type of output value(s)
array()
>>> np.cumsum(a,axis=0)      # sum over rows for each of the 3 columns
array([,
       ])
>>> np.cumsum(a,axis=1)      # sum over columns for each of the 2 rows
array([[ 1,3,6],
       [ 4,9, 15]])
页: [1]
查看完整版本: NumPy np.cumsum累计求和的用法