开发者

accumulate numpy array for just one column

开发者 https://www.devze.com 2023-02-14 17:38 出处:网络
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]])

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

精彩评论

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