code: def _ndcg_score(tp, k_range, k_list, y_true_count):
      """Normalized Discounted Cumulative Gain."""
      # Hard coded the relevance to 1.0.
      discounted_gain = 1.0 / np.log2(k_range + 1)
      discounted_cumulative_gain = np.cumsum(
          np.where(tp > 0, discounted_gain, 0.0), axis=1
      )
      ideal_discounted_gain = np.where(
          k_range > y_true_count[:, np.newaxis], 0.0, discounted_gain
      )
      ideal_discounted_cumulative_gain = np.cumsum(
          ideal_discounted_gain, axis=1
      )
      result = (
          discounted_cumulative_gain[:, k_list - 1]
          / ideal_discounted_cumulative_gain[:, 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 12 for calling a global function with example usage: _ndcg_score(tp, k_range, k_list, y_true_count) and returns: result