evolution rate python

Solutions on MaxInterview for evolution rate python by the best coders in the world

showing results for - "evolution rate python"
Ariana
15 Jul 2018
1'''RETURN EVOLUTION RATE FOR A LIST (WITH COMPREHENSION)'''
2
3nums = [120,150,230,190]
4
5#LISTE COMPREHENSION
6rates = [((nums[i+1] - nums[i]) / nums[i]) for i in range(len(nums)-1)]
7rates.insert(0, np.nan)
8
9print(rates)
10>>> [nan, 0.25, 0.53.., -0.17..]
11
12#STANDARD
13rates = []
14for i in range((len(nums)-1)):
15    rates.append( (nums[i+1] - nums[i]) / nums[i] )
16rates.insert(0,np.nan)
17
18print(rates)
19>>> [nan, 0.25, 0.53.., -0.17..]
queries leading to this page
evolution rate pythonevolution rate python