code: def find_matches_by_distance(cos_vects, cut_dist):
      
      dist_rad = np.radians(cut_dist)
      cos_t_cut = np.cos(dist_rad)
      nsrc = cos_vects.shape[1]
      match_dict = {}
      for i, v1 in enumerate(cos_vects.T):
          cos_t_vect = (v1 * cos_vects.T).sum(1)
          cos_t_vect[cos_t_vect < -1.0] = -1.0
          cos_t_vect[cos_t_vect > 1.0] = 1.0
          mask = cos_t_vect > cos_t_cut
          acos_t_vect = np.ndarray(nsrc)
          # The 1e-6 is here b/c we use 0.0 for sources that failed the cut elsewhere.
          # We should maybe do this better, but it works for now.
          acos_t_vect[mask] = np.degrees(np.arccos(cos_t_vect[mask])) + 1e-6
          for j in np.where(mask[:i])[0]:
              match_dict[(j, i)] = acos_t_vect[j]
  
      return match_dict
docs: Find all the pairs of sources within a given distance of each
      other.
  
      Parameters
      ----------
      cos_vects : np.ndarray(e,nsrc)    
          Directional cosines (i.e., x,y,z component) values of all the
          sources
  
      cut_dist : float    
          Angular cut in degrees that will be used to select pairs by
          their separation.
  
      Returns
      -------
      match_dict : dict((int,int):float).    
         Each entry gives a pair of source indices, and the
         corresponding distance