code: def precision_at_k(ranking, k):
      """
      Score is precision @ k
      Relevance is binary (nonzero is relevant).
  
      :param ranking: Relevance scores (list or numpy) in rank order (first element is the first item)
      :type ranking: list, np.array
  
      :param k: length of ranking
      :type k: int
  
      :return: Precision @ k
      :rtype: float
  
      """
  
      assert k >= 1
      ranking = np.asarray(ranking)[:k] != 0
      if ranking.size != k:
          raise ValueError("Relevance score length < k")
      return np.mean(ranking)
  
imports: import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: precision_at_k(ranking, k) and returns: np