Premium problem76. Rolling Windows (shift by 1)

Hard Locked

Given 1-D array Z, build a 2-D array whose first row is the first window elements and each subsequent row is shifted by 1 relative to the previous row (i.e. all contiguous windows of length window over Z, in order).

Input

Z = [0 1 2 3 4 5 6 7 8 9]
window = 3

Output

[[0 1 2]
 [1 2 3]
 [2 3 4]
 [3 4 5]
 [4 5 6]
 [5 6 7]
 [6 7 8]
 [7 8 9]]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)