一维NumPy数组的运行累积和 [英] Running Cumulative sum of 1d NumPy Array
本文介绍了一维NumPy数组的运行累积和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像
x=np.array([1,2,3,4])
x=np.array([1,2,3,4])
我想创建另一个numpy数组y,它是x的累加和,所以
I want to create another numpy array y which is the cumulative sum of x, so that
y=np.array([1,3,6,10])
y=np.array([1,3,6,10])
执行num-Pythonic的一种好方法是什么?
What is a good num-Pythonic way to do this?
推荐答案
y = np.cumsum(x)
请参见 http://docs.scipy.org/doc /numpy/reference/generation/numpy.cumsum.html
这篇关于一维NumPy数组的运行累积和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文