code: def calculate_ap(rec, prec):
      """
      Computes the AP under the precision recall curve.
      """
      rec, prec = rec.reshape(rec.size, 1), prec.reshape(prec.size, 1)
      z, o = np.zeros((1, 1)), np.ones((1, 1))
      mrec, mpre = np.vstack((z, rec, o)), np.vstack((z, prec, z))
      for i in range(len(mpre) - 2, -1, -1):
          mpre[i] = max(mpre[i], mpre[i + 1])
  
      indices = np.where(mrec[1:] != mrec[0:-1])[0] + 1
      ap = 0
      for i in indices:
          ap = ap + (mrec[i] - mrec[i - 1]) * mpre[i]
      return ap
  
label_desc: Use image node_id 1 for calling a global function with example usage: calculate_ap(rec, prec) and returns: ap