code: def score_ap_from_ranks_1(ranks, nres):
      """
      Compute the average precision of one search.
  
      Args:
          ranks: ordered list of ranks of true positives
          nres: total number of positives in dataset
  
      Returns:
          ap (float): the average precision following the Holidays and the INSTRE package
      """
      # accumulate trapezoids in PR-plot
      ap = 0.0
      # All have an x-size of:
      recall_step = 1.0 / nres
      for ntp, rank in enumerate(ranks):
          # y-size on left side of trapezoid:
          # ntp = nb of true positives so far, rank = nb of retrieved items so far
          if rank == 0:
              precision_0 = 1.0
          else:
              precision_0 = ntp / float(rank)
          # y-size on right side of trapezoid: ntp and rank are increased by one
          precision_1 = (ntp + 1) / float(rank + 1)
          ap += (precision_1 + precision_0) * recall_step / 2.0
      return ap
  
imports: import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: score_ap_from_ranks_1(ranks, nres) and returns: ap