1

I'd like to split arrays into multiple arrays with overlapping

given = [1,2,3,4,5,6,7,8,9]

There are two parameter, w=2 (step size is 2), m=1 (overlap 1 element)

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

opposed to regular np.split_array(l, range(1,8,2))

[array([1]), array([2, 3]), array([4, 5]), array([6, 7]), array([8, 9])]

Maybe I could do split twice, one with at every w and one with every w+m and concatenate the arrays..

eugene
  • 39,839
  • 68
  • 255
  • 489
  • There's a new windowing function. But you could also use repeated slices. (Split array uses slices) – hpaulj May 23 '21 at 02:41
  • 1
    With the newish, safer `as_strided`,: `np.lib.stride_tricks.sliding_window_view(np.arange(1,10),3)[::2]` – hpaulj May 23 '21 at 03:40

0 Answers0