0

I have numpy array [1 2 3 4 5 6 7 8 9 10 11 12]. Want to divide in sub-arrays of size 6 with 3 overlap [1 2 3 4 5 6] [4 5 6 7 8 9] [7 8 9 10 11 12] in the above case.

I want to make it generalized. Say I have a thousand size array. I want to get sub-arrays of 100 size with 50 overlap.

Also, the overlap size is always half of sub-array size.

Abhishek Bhatia
  • 9,404
  • 26
  • 87
  • 142

1 Answers1

2

Try this:

>>> size = 6
>>> overlap = 3
>>> z = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
>>> zip(*[z[i:] for i in range(size)])[::overlap]
[(1, 2, 3, 4, 5, 6), (4, 5, 6, 7, 8, 9), (7, 8, 9, 10, 11, 12)]
Irshad Bhat
  • 8,479
  • 1
  • 26
  • 36