code: def _conditional_entropy_compute(confmat: Tensor) -> Tensor:
      r"""Compute Conditional Entropy Statistic based on a pre-computed confusion matrix.
  
      .. math::
          H(X|Y) = \sum_{x, y ~ (X, Y)} p(x, y)\frac{p(y)}{p(x, y)}
  
      Args:
          confmat: Confusion matrix for observed data
  
      Returns:
          Conditional Entropy Value
  
      """
      confmat = _drop_empty_rows_and_cols(confmat)
      total_occurrences = confmat.sum()
      # iterate over all i, j combinations
      p_xy_m = confmat / total_occurrences
      # get p_y by summing over x dim (=1)
      p_y = confmat.sum(1) / total_occurrences
      # repeat over rows (shape = p_xy_m.shape[1]) for tensor multiplication
      p_y_m = p_y.unsqueeze(1).repeat(1, p_xy_m.shape[1])
  
      # entropy calculated as p_xy * log (p_xy / p_y)
      return torch.nansum(p_xy_m * torch.log(p_y_m / p_xy_m))
  
file_path: torchmetrics/src/torchmetrics/functional/nominal/theils_u.py
imports: import itertools
  from typing import Optional
  import torch
  from torch import Tensor
  from typing_extensions import Literal
  from torchmetrics.functional.classification.confusion_matrix import _multiclass_confusion_matrix_update
  from torchmetrics.functional.nominal.utils import _drop_empty_rows_and_cols, _handle_nan_in_data, _nominal_input_validation
label_desc: Use image node_id 1 for calling a global function with example usage: _conditional_entropy_compute(confmat) and returns: torch