I have algorithm of calculation of the difference between neighboring elements in pure python:
a = range(1000000) #it's numpy array in my case prev = a[0] b = [0, ] for i in a[1:]: b.append(i - prev) prev = i
Is there any way to rewrite this functions with Numpy?
There is the diff
method:
a = range(5) # python list of numpy array np.diff(a)
returns
array([1, 1, 1, 1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With