Running Cumulative sum of 1d NumPy Array

前端 未结 2 409
心在旅途
心在旅途 2021-01-17 11:24

I have a numpy array like

x=np.array([1,2,3,4])

I want to create another numpy array y which is the cumulative sum of x, so that

相关标签:
2条回答
  • 2021-01-17 11:48

    Another option is:

    y = np.add.accumulate(x)
    

    which is often times faster than np.cumsum even though the documentation says they are equivalent.

    0 讨论(0)
  • 2021-01-17 11:53
    y = np.cumsum(x)
    

    See http://docs.scipy.org/doc/numpy/reference/generated/numpy.cumsum.html

    0 讨论(0)
提交回复
热议问题