I have a list of lists. For example:
a = [[38, 2, 33, 8, 17, 8, 39, 36, 34, 17, 26, 22, 10, 2, 37, 17, 33, 2, 23, 40, 38, 0, 40, 14, 3, 30],
[38, 20, 31, 33, 0, 30, 33, 2, 8, 34, 30, 36, 10, 2, 38, 35, 8, 40, 0, 25, 2, 30, 2, 25]]
This list has about 200 sub-lists (I've provided 2). I am looking for a way to output an array containing a sliding window with an arbitrary before and after number of values. For example, with two preceding values and three following values, I am trying to get:
[[_, _, 38, 2, 33, 8],
[_, 38, 2, 33, 8, 17],
[38, 2, 33, 8, 17, 9],
...,
[14, 3, 30, _, _, _,],
[_, _, 38, 20, 31, 33],
...]
I will need to repeat this operation many times (for different sub-lists), and thus speed is important. I am under the impression that converting the data to a Numpy array to use the answer here may be too slow (since each list is of a different length I am guessing I need to instantiate multiple np.arrays). Is there a nice way to do this? Thank you!