evolution rate python code example
Example: evolution rate python
'''RETURN EVOLUTION RATE FOR A LIST (WITH COMPREHENSION)'''
nums = [120,150,230,190]
#LISTE COMPREHENSION
rates = [((nums[i+1] - nums[i]) / nums[i]) for i in range(len(nums)-1)]
rates.insert(0, np.nan)
print(rates)
>>> [nan, 0.25, 0.53.., -0.17..]
#STANDARD
rates = []
for i in range((len(nums)-1)):
rates.append( (nums[i+1] - nums[i]) / nums[i] )
rates.insert(0,np.nan)
print(rates)
>>> [nan, 0.25, 0.53.., -0.17..]