title: How can I detect flipping in a time series?
body: <p>For a system that operates on different operational modes, I want to reduce the flipping between modes. For this the detection of flipping and the correction is needed.</p>
  <p>Let's assume we have a sequence where modes switch frequently:</p>
  <pre><code>before = [0,0,0,(1,0),1,1,1,2,2,(1,2),1,1,1,(0,1),0]   # parenthesis indicate flipping
  </code></pre>
  <p>I would like to kind of swap only at (changing points) to get :</p>
  <pre><code>after  = [0,0,0,(0,1),1,1,1,2,2,(2,1),1,1,1,(1,0),0]   # parenthesis indicate corrections
  </code></pre>
  <p>How can I achieve that?</p>