title: numpy / pandas diff: spread the diff equally over the enclosed nan element
body: <p>I have a numpy array (which is not necessarily sorted):</p>
  
  <pre><code>[2.0, 3.0, nan, nan, nan, 5.0]
  </code></pre>
  
  <p>I want to calculate the difference on this array. The difference between the last element, 5, and the second element, 3, is 2. I want this difference of 2 to be spread over the enclosed nan elements of my numpy array.  If i try numpy.diff (I also tried using masked arrays) i get the result: </p>
  
  <p><code>[nan, 1, nan, nan, nan, nan]</code>.</p>
  
  <p>where the result should look like the following:</p>
  
  <pre><code>[nan, 1, 0.5, 0.5, 0.5, 0.5]
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I got answers for the specific case above but the given answers are not valid in a more general form. for example if we have trailing/leading nan's and when we have alternately nan and values. for example:</p>
  
  <pre><code>[nan, nan, 2.0, 3.0, nan, nan, nan, 5.0, nan, 6.0, nan]
  </code></pre>