I have a numpy array that looks like this
X = numpy.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
I want to construct a view of the array, grouping its elements in a moving window (of size 4 in my example). My result should look like this :
M = numpyp.array([[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6],
[4, 5, 6, 7],
[5, 6, 7, 8],
[6, 7, 8, 9]]
This is called a Hankel matrix, and I can use scipy.linalg.hankel to achieve that, or simply execute :
M=numpy.array([X[i:i+4] for i in range(len(X)-3)])
But I want to avoid the reallocation.
Is there a manner to have a view in the array X as the Hankel matrix described above without reallocation?