开发者

accumulate numpy array for just one column

I have a NumPy array, i want to accumulate the values of one column, say the 2nd column.

a = np.array([[1,2],[2,4]])
# some kind of accumulate function that accumulates just one column:
np.add.accumulate(a, 2)

a should now be [[1,2],[2,6]]

Is there a way t开发者_开发技巧o do this in NumPy?


a = np.array([[1,2],[2,4]])
np.add.accumulate(a[:,1], out=a[:,1])

a is now:

array([[1, 2],
       [2, 6]])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜