Reputation: 1581
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 to do this in NumPy?
Upvotes: 1
Views: 1161
Reputation: 43680
a = np.array([[1,2],[2,4]])
np.add.accumulate(a[:,1], out=a[:,1])
a
is now:
array([[1, 2],
[2, 6]])
Upvotes: 2