I am trying to do some anomaly detection in one of my assignments and I am trying to create sliding windows, but I want to make them so that one window does not overlap with the other. For example array = [1, 2, 3, 4, 5, 6] I want to get to this result result = [[1, 2, 3], [4, 5, 6]] Apparently you can use either as_strided or sliding_window_view methods, but the second one did not work so well, but if anyone knows a solution to this it is highly appreciated
Your 1d array:
A simple reshape:
sliding windows creates (3,) windows, with full overlap
from that we can easily slice out the no-overlap elements:
To use
as_strided, we have to understandstrides.sliding_windowsdoes this thinking for us:That
12is(3*4)The equivalent of sliding_windows:
sliding_windowsis easier to use, since we don't need to know about strides, and it makes sure that the result is the correct size.