looping through ex post cumsums

Viewed 11

Say I have an array

input = [1,2,3,4,5]

I want to calculate the element-wise difference such that the resultant array will be like:

first element stays the same

result = [1, ...  

second element will be second input element minus cum sum of whats currently in the result vector so 2-1 = 1

so eventually for this particular input you get

result = [1,1,1,1,1]

I thought about using

[y - x.cumsum[x] for x, y in zip(R, R[1:])]

didn't work alternatively settled on

np.array(d1)[1:]-np.cumsum(np.array(d1))[:-1]

This too is incorrect. I would appreciate your help. ty

0 Answers
Related