title: How to align two unequal sized timeseries numpy array?
body: <p>I have two numpy arrays containing timeseries (unix timestamps).<br />
  I <strong>want to find pairs of timestamps</strong> (1 from each array) whose <strong>difference</strong> is within a <strong>threshold</strong>.</p>
  <p>For achieving this, I need to align two of the time series data into two arrays, such that each index has its closest pair. (In case of two timestamps in arrays equally close to another timestamp in another array, I don't mind choosing either one, as the count of pairs is more important than the actual values.)</p>
  <p>So the aligned data set will have <strong>two</strong> arrays of <strong>same size</strong>, plus a smaller array being filled with empty data .</p>
  <p>I was thinking of using <code>timeseries</code> package and the <code>align</code> function.<br />
  But am not sure <strong>how to use aligned for my data</strong> which is a timeseries.</p>
  <p>Example consider two timeseries arrays:</p>
  <pre><code>ts1=np.array([ 1311242821.0, 1311242882.0, 1311244025.0, 1311244145.0, 1311251330.0, 
                 1311282555.0, 1311282614.0])
  ts2=np.array([ 1311226761.0, 1311227001.0, 1311257033.0, 1311257094.0, 1311281265.0])
  </code></pre>
  <p>Output sample:</p>
  <p>Now for <code>ts2[2] (1311257033.0)</code>, its closest pair should be <code>ts1[4] (1311251330.0)</code> because the difference is <code>5703.0</code>, which is within the <code>threshold</code>, and it is the smallest. Now that <code>ts2[2]</code> and <code>ts1[4]</code> <strong>are already paired</strong> they should be left out of other calculations.</p>
  <p><strong>Such Pairs should be found</strong>, so the Output array might be longer than the actual arrays</p>
  <blockquote>
  <p>abs(ts1[0]-ts2[0]) = 16060<br />
  <strong>abs(ts1[0]-ts2[1]) = 15820</strong> //pair<br />
  abs(ts1[0]-ts2[2]) = 14212<br />
  abs(ts1[0]-ts2[3]) = 14273<br />
  abs(ts1[0]-ts2[4]) = 38444</p>
  <hr />
  <p>abs(ts1[1]-ts2[0]) = 16121<br />
  abs(ts1[1]-ts2[1]) = 15881<br />
  abs(ts1[1]-ts2[2]) = 14151<br />
  abs(ts1[1]-ts2[3]) = 14212<br />
  abs(ts1[1]-ts2[4]) = 38383</p>
  <hr />
  <p>abs(ts1[2]-ts2[0]) = 17264<br />
  abs(ts1[2]-ts2[1]) = 17024<br />
  abs(ts1[2]-ts2[2]) = 13008<br />
  abs(ts1[2]-ts2[3]) = 13069<br />
  abs(ts1[2]-ts2[4]) = 37240</p>
  <hr />
  <p>abs(ts1[3]-ts2[0]) = 17384<br />
  abs(ts1[3]-ts2[1]) = 17144<br />
  abs(ts1[3]-ts2[2]) = 12888<br />
  abs(ts1[3]-ts2[3]) = 17144<br />
  abs(ts1[3]-ts2[4]) = 37120</p>
  <hr />
  <p>abs(ts1[4]-ts2[0]) = 24569<br />
  abs(ts1[4]-ts2[1]) = 24329<br />
  <strong>abs(ts1[4]-ts2[2]) = 5703</strong> //pair<br />
  abs(ts1[4]-ts2[3]) = 5764<br />
  abs(ts1[4]-ts2[4]) = 29935</p>
  <hr />
  <p>abs(ts1[5]-ts2[0]) = 55794<br />
  abs(ts1[5]-ts2[1]) = 55554<br />
  abs(ts1[5]-ts2[2]) = 25522<br />
  abs(ts1[5]-ts2[3]) = 25461<br />
  <strong>abs(ts1[5]-ts2[4]) = 1290</strong> //pair</p>
  <hr />
  <p>abs(ts1[6]-ts2[0]) = 55853<br />
  abs(ts1[6]-ts2[1]) = 55613<br />
  abs(ts1[6]-ts2[2]) = 25581<br />
  abs(ts1[6]-ts2[3]) = 25520<br />
  abs(ts1[6]-ts2[4]) = 1349</p>
  <hr />
  </blockquote>
  <p>So the pairs are: (<code>ts1[0],ts2[1]), (ts1[4],ts2[2]), (ts1[5],ts2[4]</code>)<br />
  The rest of elements should have <code>null</code> as their pair<br />
  The final two arrays will be of size 9.</p>
  <p>Please let me know if this question is clear.</p>