Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy - get multiply difference between neighboring elements [duplicate]

Tags:

python

diff

numpy

Is there a function that returns an array with the results of dividing the next element by the previous one? Like a "diff()", but with dividing

Not-numpy-example:

t=[1,3,6,24,36]
t1 = [j / i for i, j in zip(t[:-1], t[1:])]
like image 815
Dennis Meissel Avatar asked Sep 17 '26 22:09

Dennis Meissel


1 Answers

Assign t to a numpy array:

t = np.array(t)

Simply divide:

>>> t[1:] / t[:-1]
array([3. , 2. , 4. , 1.5])
like image 73
user3483203 Avatar answered Sep 20 '26 10:09

user3483203



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!