I have an array consisting of two values a and b. (In my case these are strings). The array, in the physical interpretation, is periodic, so if N
is the length of the array arr
, then arr[n+N]=arr[n]
. How do I roll the array such that it has the form [a, a, ..., a, b, ..., b, b]
i.e. sorted or grouped into two parts within the context of the definition of array (physically it will remain the same because I will roll the physical quantity in the same way too, of which this array is a label)?
I tried np.roll(arr, len(arr) - arr.index('r'))
, but this doesn’t take into account the periodicity.