I am currently working on a data set that needs to know the gap between a value on an array and the value below it then divide the result with current array value
For example :
result = 0
arr = [...]
for i in range(len(arr)):
if i > 0:
result += (arr[i] - arr[i - 1]) / arr[i]
But I would like to do this, in a "one-liner" scenario and preferably without any loops as to optimize performance, are there any ways to do this?
for example I am looking for something like :
arr = list(range(min, max))
is equivalent to :
arr = []
for i in range(max - min):
arr.append(i + min)
My apologies if this is a noob-ish question, but I hope you can help me :)