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]])
加载中,请稍侯......
精彩评论