2

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:])]
Dennis Meissel
  • 911
  • 13
  • 27

1 Answers1

4

Assign t to a numpy array:

t = np.array(t)

Simply divide:

>>> t[1:] / t[:-1]
array([3. , 2. , 4. , 1.5])
user3483203
  • 48,205
  • 9
  • 52
  • 84