3

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
  • 1,825
  • 1
  • 21
  • 33

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
  • 50,081
  • 9
  • 65
  • 94