Restructuring repeated tensor data using as_strided

unfold should work:

out = t.unfold(dimension=3, size=5, step=2)
print(out)
# tensor([[[[[ 1,  2,  3,  4,  5],
#            [ 3,  4,  5,  6,  7],
#            [ 5,  6,  7,  8,  9],
#            [ 7,  8,  9, 10, 11]],

#           [[99, 98, 97, 96, 95],
#            [97, 96, 95, 94, 93],
#            [95, 94, 93, 92, 91],
#            [93, 92, 91, 90, 98]]]]])
1 Like