I want to subtract consecutive numbers in an array a
:
a = [1, 3, 4, 7, 9, 2]
The resulting array should be:
res = [2, 3, 7]
So I want to subtract 1-3, 4-7 and then 9-2 in Python and get the absolute value. How can I make a code or function to do this?
I tried doing
res = a[0:] - a[:+1]
but this gives me
res = [-2, -3, -6, -8, -1]