Approach # 1: Using broadcasting -
def broadcasting_app(a, L, S ):
Approach # 2: Using More Effective NumPy strides -
def strided_app(a, L, S ):
Run Example -
In [143]: a Out[143]: array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) In [144]: broadcasting_app(a, L = 5, S = 3) Out[144]: array([[ 1, 2, 3, 4, 5], [ 4, 5, 6, 7, 8], [ 7, 8, 9, 10, 11]]) In [145]: strided_app(a, L = 5, S = 3) Out[145]: array([[ 1, 2, 3, 4, 5], [ 4, 5, 6, 7, 8], [ 7, 8, 9, 10, 11]])