If I have a 2D tensor (matrix) of size say (5,6), how do I transform it into a (10,3) matrix where each column in the resultant matrix is formed by stacking two consecutive columns in the initial matrix, with a step size of 2. That is, first two columns in the initial matrix are stacked to form the first column in the resultant matrix , 3rd and 4th columns in the initial matrix stacked to obtain the second column in the new matrix and likewise

In a more general sense I want to slide a window, width-wise where all columns in a window are stacked to form single column

Thank you for the quick response. For a more general case, suppose If I want to move a sliding window with overlapping columns, is there any approach without writing any loops.

For example in y I want first column to be first and second columns of x stacked, and second column of y to be second and third columns of x stacked together.