I have a tensor of shape (size, 1) and I want to convert it into of shape (size, lookback, 1) by shifting its values. A pandas equivalent is below
size = 7
lookback = 3
data = pd.DataFrame(np.arange(size), columns=['out']) # input
y = np.full((len(data), lookback, 1), np.nan) # required/output
for j in range(lookback):
y[:, j, 0] = data['out'].shift(lookback - j - 1).fillna(method="bfill")
How can I acheive similar in pytorch?
Example input:
[0, 1, 2, 3, 4, 5, 6]
Desired output:
[[0. 0. 0.]
[0. 0. 1.]
[0. 1. 2.]
[1. 2. 3.]
[2. 3. 4.]
[3. 4. 5.]
[4. 5. 6.]]