Running Cumulative sum of 1d NumPy Array

前端 未结 2 436
心在旅途
心在旅途 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.

提交回复
热议问题