title: Finding match in 2 arrays based on datetime64 type column
body: <p>I am pretty new to the world of python and numpy and I need some help with coding following:</p>
  
  <p>My "index" column in both arrays is datetime64.
  I want to find in array N all rows matching said index from R array and make final array with matching contents of both, say R2.</p>
  
  <p>To complicate things - in array N you sometimes will not find its match, 
  so here comes RLookUp, which is all possible/allowed times to be looked for (with closest as best match)</p>
  
  <p>I tried with mapping but I was not very successful.</p>
  
  <p>Any help with solving this will be much appreciated.</p>
  
  <pre><code>import numpy as np
  
  #######################################
  ### CONST / VAR / SETTINGS
  
  laMinutes = 2 #look ahead minutes
  lbMinutes = 0 #look back minutes
  
  #chronological order, with seconds
  N = np.array([
  [np.datetime64('2013-05-02 10:00:00', 'm'), 1.11, 1.111],
  [np.datetime64('2013-05-02 10:30:00', 'm'), 2.22, 2.222],
  [np.datetime64('2013-05-02 11:02:00', 'm'), 3.33, 3.333],
  [np.datetime64('2013-05-02 11:30:00', 'm'), 4.44, 4.444],
  [np.datetime64('2013-05-02 12:05:00', 'm'), 5.55, 5.555]
  ])
  
  #print(N)
  
  
  #reversed (the newest first), with minutes
  R = np.array([
  [ 555, np.datetime64('2013-05-02 12:00')],
  [ 333, np.datetime64('2013-05-02 11:00')],
  [ 111, np.datetime64('2013-05-02 10:00')]
  ])
  #print(R)
  
  #######################################
  ### MAIN
  
  
  RLookUp = np.empty( (0, 1), dtype='&lt;M8[m]') #array for all possible times derived from R
  
  #adds all possible look ahead outcomes
  for row in range(0, len(R)):
      for laMinute in range (-lbMinutes, laMinutes+1):
          timeR = R[row,1] + np.timedelta64(laMinute,'m')
          rowN = np.searchsorted(N[:, 0], timeR, side='l')
          if rowN == len(N):
              print(timeR, ' : ', 'NOT FOUND')
          else:            
              print(timeR, ' : ', rowN)
  
          RLookUp = np.append(RLookUp, np.array([[timeR]]), axis=0) 
  
  #TODO: sorting necessary ?
  RLookUp = np.sort(RLookUp, axis=0)
  print('\n RLookUp: \n', RLookUp) 
  
  
  #will not work, some RLookUp times does not exist in N
  #mapRLookUp = dict( zip(RLookUp[:,0], (range(len(RLookUp)))))
  #print('\n mapRLookUp: \n', mapRLookUp) 
  #N2 = np.array([    N[mapRLookUp[key], 0:3] for key in RLookUp[:,1]    ])
  #print('\n N2: \n', N2) 
  
  
  
  #R2 = np.hstack((R, N2))  
  #print('\n R2: \n', R2)      
  </code></pre>