decay = 0.1
data = np.array([100,200,300,400,500])
y = np.zeros(len(data))
for i in range(len(data)):
if i == 0:
y[i] = (1.0 - decay) * data[i]
else:
y[i] = (1.0 - decay) * data[i] + (decay * y[i - 1])
y
Output:
array([ 90. , 189. , 288.9 , 388.89 , 488.889])
Now this I'm cut shorting by indexing
decay = 0.1
data = np.array([100,200,300,400,500])
data = (1.0 - decay) * data
data[1:] = data[1:] + decay * data[0:-1]
data
Output:
array([ 90., 189., 288., 387., 486.])
I feel here I'm doing some mistake or missing float values or not getting cumulative value as both the output aren't matching, the first output is the correct one, what is the mistake here?