Issue
>>> jj = [1,3,9,4,5,6,1,2,4,1,7,9,0,4,1,9]
>>> np.diff(jj)
[ 2 6 -5 1 1 -5 1 2 -3 6 2 -9 4 -3 8]
np.diff gives difference between the consecutive numbers. I am looking for difference between every element with a gap of 3 values
input: [1,3,9,4,5,6,1,2,4,1,7,9,0,4,1,9]
difference between the bold values output : [3,-3,0,-1,-9]
Solution
First, you can use slicing
with step : 3
. then use numpy.diff
. You can read understanding-slicing
import numpy as np
a = np.array([1,3,9,4,5,6,1,2,4,1,7,9,0,4,1,9])
b = np.diff(a[::3])
print(b)
Output: array([ 3, -3, 0, -1, 9])
Answered By - I'mahdi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.