code: def find_closest_matches(detections, annotations):
      """
      Find the closest annotation for each detection.
  
      Parameters
      ----------
      detections : list or numpy array
          Detected events.
      annotations : list or numpy array
          Annotated events.
  
      Returns
      -------
      indices : numpy array
          Indices of the closest matches.
  
      Notes
      -----
      The sequences must be ordered.
  
      """
      # make sure the arrays have the correct types
      detections = np.asarray(detections, dtype=float)
      annotations = np.asarray(annotations, dtype=float)
      # TODO: right now, it only works with 1D arrays
      if detections.ndim > 1 or annotations.ndim > 1:
          raise NotImplementedError(
              "please implement multi-dim support"
          )
      # if no detections or annotations are given
      if len(detections) == 0 or len(annotations) == 0:
          # return a empty array
          return np.zeros(0, dtype=int)
      # if only a single annotation is given
      if len(annotations) == 1:
          # return an array as long as the detections with indices 0
          return np.zeros(len(detections), dtype=int)
      # solution found at: http://stackoverflow.com/questions/8914491/
      indices = annotations.searchsorted(detections)
      indices = np.clip(indices, 1, len(annotations) - 1)
      left = annotations[indices - 1]
      right = annotations[indices]
      indices -= detections - left < right - detections
      # return the indices of the closest matches
      return indices
  
imports: from __future__ import absolute_import, division, print_function
  import numpy
  from .None import chords, beats, notes, onsets, tempo
  from .beats import BeatEvaluation, BeatMeanEvaluation
  from .chords import ChordEvaluation, ChordMeanEvaluation, ChordSumEvaluation
  from .key import KeyEvaluation, KeyMeanEvaluation
  from .notes import NoteEvaluation, NoteMeanEvaluation, NoteSumEvaluation
  from .onsets import OnsetEvaluation, OnsetMeanEvaluation, OnsetSumEvaluation
  from .tempo import TempoEvaluation, TempoMeanEvaluation
label_desc: Use image node_id 1 for calling a global function with example usage: find_closest_matches(detections, annotations) and returns: indices, np, np