How to exponentially decay a value along an axis?
I have a tensor of shape (sequence_length,batch_size,1) (which is (5,5,1) in the following example). Every sequence has a single entry that I want to exponentially decay along the sequence (for example with a decay factor of 0.99) for n steps (here: n = 2). 

Example:



Is there an efficient way to realize something like that (either in PyTorch or numpy).

Edit (visualizing the additive nature):



This looks like convolution to me:

import numpy as np
from scipy.ndimage import convolve1d

# just for printing:
import numpy.lib.recfunctions as nlr
def show(x): print(nlr.unstructured_to_structured(x))

a = "00000","00100","10000","03502","00010"
A = np.array(a).view('U1').reshape(5,5,1).astype(float)

show(A)
# [[(0.,) (0.,) (0.,) (0.,) (0.,)]
#  [(0.,) (0.,) (1.,) (0.,) (0.,)]
#  [(1.,) (0.,) (0.,) (0.,) (0.,)]
#  [(0.,) (3.,) (5.,) (0.,) (2.,)]
#  [(0.,) (0.,) (0.,) (1.,) (0.,)]]

show(convolve1d(A,np.r_[np.logspace(2,0,3,base=0.99),0,0],axis=0,mode="constant"))
# [[(0.9801,) (0.    ,) (0.99  ,) (0.    ,) (0.    ,)]
#  [(0.99  ,) (2.9403,) (5.9005,) (0.    ,) (1.9602,)]
#  [(1.    ,) (2.97  ,) (4.95  ,) (0.9801,) (1.98  ,)]
#  [(0.    ,) (3.    ,) (5.    ,) (0.99  ,) (2.    ,)]
#  [(0.    ,) (0.    ,) (0.    ,) (1.    ,) (0.    ,)]]

