I am given an array X and I am asked to return another array Y where y[t] = x[t] + x[t-1] and y[0] = 0 without using a for loop in Python.
What I can think of is using rolling sum but I am not sure if this is the fastest way since I need to convert x into a dataframe/ a series for rolling to work. Is there a faster way to do that? Thanks!
df = pd.DataFrame(X).rename(columns={0: 'X'})
df['Y'] = df['X'].rolling(2).sum().fillna(0)
Y = df['Y'].values