I have an array given as
x = [1 1 1 2 2 1 1 1]
I'd like to know a way I could go through each individual element in the array, and getting a value for how many steps the number stays at the same value. For instance, for this example, the output I would be looking for would be
y = [2 1 0 1 0 2 1 0]
Where the first value of 1 stays constant for another 2 steps, the second stays constant for one more step etc.
Best Answer