File size: 196 Bytes
9839b09
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
import numpy as np


def discounted_cumsum(x: np.ndarray, gamma: float) -> np.ndarray:
    dc = x.copy()
    for i in reversed(range(len(x) - 1)):
        dc[i] += gamma * dc[i + 1]
    return dc