scipy.signal lfilter 1

scipy.signal lfilter

def discount(x, gamma):
  """
  Compute discounted sum of future values
  out[i] = in[i] + gamma * in[i+1] + gamma^2 * in[i+2] + ...
  """
  return signal.lfilter([1], [1, -gamma], x[::-1], axis=0)[::-1] 

Here is what the above code is Doing:
1. The first line is a function definition. It takes two arguments, x and gamma, and returns a value.
2. The second line is a docstring. It’s a special kind of comment that describes what the function does.
3. The third line is a call to the lfilter function from the scipy.signal module.
4. The fourth line reverses the array.
5. The fifth line reverses the array again.

Similar Posts