code: def prec(recommendations, ground_truth):
      n_users, n_items = ground_truth.shape
      K = recommendations.shape[1]
      user_idx = np.repeat(np.arange(n_users), K)
      item_idx = recommendations.flatten()
      relevance = ground_truth[user_idx, item_idx].reshape((n_users, K))
      hit = relevance.any(axis=1).mean()
      return hit
  
file_path: dgl/examples/pytorch/pinsage/evaluation.py
imports: import argparse
  import pickle
  import dgl
  import numpy
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: prec(recommendations, ground_truth) and returns: hit