title: numpy: how interpolate between two arrays for various timesteps?
body: <p>I'm looking for a way to do a simple linear interpolation between two <code>numpy</code> arrays that represent a start and endpoint in time.   </p>
  
  <p>The two arrays have the same length:</p>
  
  <pre><code>fst = np.random.random_integers(5, size=(10.))
  &gt;&gt;&gt; array([4, 4, 1, 3, 1, 4, 3, 2, 5, 2])
  snd = np.random.random_integers(5, size=(10.))
  &gt;&gt;&gt; array([1, 1, 3, 4, 1, 5, 5, 5, 4, 3])
  </code></pre>
  
  <p>Between my start and endpoint there are 3 timesteps. How can I interpolate between <code>fst</code> and <code>snd</code>? I want to be able, taking the first entry of <code>fst</code> and <code>snd</code> as an example, to retrieve the value of each timestep like </p>
  
  <pre><code>np.interp(1, [1,5], [4,1])    
  np.interp(2, [1,5], [4,1])
  ...
  # that is
  np.interp([1,2,3,4,5], [1,5], [4,1])
  &gt;&gt;&gt; array([ 4.  ,  3.25,  2.5 ,  1.75,  1.  ])
  </code></pre>
  
  <p>But than not just for the first entry but over the whole array.</p>
  
  <p>Obviously, this won't do it:</p>
  
  <pre><code>np.interp(1, [1,5], [fst,snd])
  </code></pre>
  
  <p>Well I know I get there in a loop, e.g. </p>
  
  <pre><code>[np.interp(2, [1,5], [item,snd[idx]]) for idx,item in enumerate(fst)]
  &gt;&gt;&gt; [3.25, 3.25, 1.5, 3.25, 1.0, 4.25, 3.5, 2.75, 4.75, 2.25]
  </code></pre>
  
  <p>but I believe when you are lopping over numpy arrays you are doing something fundamentally wrong.</p>