I'm having problem finding function similar to cumulative sum only I want it weighted. So with an external for loop would look something like this:
discount_rate = 0.95
rewards = [0, 0, 10] # want to translate to: [9, 9.5, 10] (approximation)
reversed_rewards = [10, 0, 0]
new_rewards = [0] * len( rewards)
previus = 0
for index in range( len( rewards)):
new_rewards[ index] = reversed_rewards[ index] + previus * discount_rate
previus = new_rewards[ index]
print( list( reversed( new_rewards)))
But this is kind of slow version if you have large reward array. Is there any existing function that would do this faster?