code: def discount(x, gamma):
      """
      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
  
      """
      assert x.ndim >= 1
      return scipy.signal.lfilter([1], [1, -gamma], x[::-1], axis=0)[
          ::-1
      ]
  
file_path: baselines/baselines/common/math_util.py
imports: import numpy
  import scipy.signal
label_desc: Use image node_id 1 for calling a global function with example usage: discount(x, gamma) and returns: scipy