code: def _average_precision(self, rec, prec):
          
          # append sentinel values at both ends
          mrec = np.concatenate(([0.], rec, [1.]))
          mpre = np.concatenate(([0.], prec, [0.]))
  
          # compute precision integration ladder
          for i in range(mpre.size - 1, 0, -1):
              mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])
  
          # look for recall value changes
          i = np.where(mrec[1:] != mrec[:-1])[0]
  
          # sum (\delta recall) * prec
          ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])
          return ap
docs: calculate average precision
  
          Params:
          ----------
          rec : numpy.array
              cumulated recall
          prec : numpy.array
              cumulated precision
          Returns:
          ----------
          ap as float