I have a numpy array which I wish to split across a certain dimension. While splitting the array, I need to prepend (to the beginning of each element) a trailing part of the previous element. For instance,
Let my array be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
. Let my split_size = 2
and pad_length = 1
. split_size
will always be a divisor of array length. My resultant splits would look like,
[random, 0, 1], [1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]
. My splits were all prepended by the last value of the previous element.
Needless to say, my arrays are multidimensional and I need an efficent vectorized way to do this along a certain dimension.
Here, I can provide the value of random
.