I would convert the 2d array into 3d with previous rows by using NumPy or native functions.
Input:
[[1,2,3], [4,5,6], [7,8,9], [10,11,12], [13,1
How about a list comprehension?
In [144]: np.array([l[i:i + 3][::-1] for i in range(0, len(l) - 2)]) Out[144]: array([[[ 7, 8, 9], [ 4, 5, 6], [ 1, 2, 3]], [[10, 11, 12], [ 7, 8, 9], [ 4, 5, 6]], [[13, 14, 15], [10, 11, 12], [ 7, 8, 9]]])