I have a dataset where it is constant sometimes with small noise. It can be on the top, it can be in the middle. I want to remove all constant part of the signal so that it compress into a smaller length.
Lets say if 200 consicutive value is same (or in a threshold limit to be considered as constant) then consider that part as constant .
Any solution code or logical suggestion will be appriciated. Thanks for your time.
I have attached a sample data google drive link in .npy format.
In the below sample image I have indicated (red) which part I want to get rid of as an example:


I came up with the following solution. The answer from @rsenne helped me to start but that was not the solution I have wanted. Please let me know if there anything I should add in my solution to improve the performance.
The resulted image looks like: