code: def discount(x, gamma):
      
      assert x.ndim >= 1
      return scipy.signal.lfilter([1],[1,-gamma],x[::-1], axis=0)[::-1]
docs: computes discounted sums along 0th dimension of x.
  
      inputs
      ------
      x: ndarray
      gamma: float
  
      outputs
      -------
      y: ndarray with same shape as x, satisfying
  
          y[t] = x[t] + gamma*x[t+1] + gamma^2*x[t+2] + ... + gamma^k x[t+k],
                  where k = len(x) - t - 1