I have a one-dimensional array whose elements are either 1 or 0. Looking at blocks of 8 elements each, I want to reverse the order of elements within a block but leave the order of blocks intact. For instance, let's say we have an array A consisting of two blocks:
A = [0,1,0,0,1,0,1,1,0,1,1,1,0,0,1,0]
After this operation, it needs to be like this:
A = [1,1,0,1,0,0,1,0,0,1,0,0,1,1,1,0]
I have currently this solution:
A.reshape(-1,8)[:,::-1].reshape(-1)
Since I am doing this operation on many and large one dimensional arrays, I want to do it as efficient as possible.
Is there a more efficient solution (like using only one reshape method)?
.reshape(-1)with.flatten()gives a bit extra performance