code: def _mean_average_precision(tp, tp_at_topks, ks, k_list, y_true_len):
      precision_all_k = tp_at_topks[:, ks - 1] / ks
      # Average Precision = (precision[k] * relevance[k]) / K where we
      # use tp > 0 as a proxy for relevance.
      relevance = tp > 0
      size_true = np.minimum(ks, y_true_len[:, np.newaxis])
      result = (
          np.cumsum(precision_all_k * relevance, axis=1) / size_true
      )
      result = result[:, k_list - 1]
      return result
  
imports: from collections.abc import Sequence
  import dataclasses
  from typing import Any
  import numpy
  from numpy import typing
  from tensorflow_model_analysis.experimental.lazytf import api
  from tensorflow_model_analysis.experimental.metrics.aggregates import _classification
label_desc: Use image node_id 9 for calling a global function with example usage: _mean_average_precision(tp, tp_at_topks, ks, k_list, y_true_len) and returns: result