This question solves half of my problem
because my sliding window can move outside the table,
e.g. for 3×3 window, two columns of the window can be on the left end of the table
and one column will be on the right end. These images show window moving to the left

I need algorithm for this sliding window, sliding window in the mentioned question doesn’t move outside the table.
You can use the modulo operation (
%) in order to confine the indexes.