Running Cumulative sum of 1d NumPy Array

前端 未结 2 430
心在旅途
心在旅途 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:53

    y = np.cumsum(x)
    

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

提交回复
热议问题