code: def to_categorical(x: Tensor, argmax_dim: int = 1) -> Tensor:
      """Convert  a tensor of probabilities to a dense label tensor.
  
      Args:
          x: probabilities to get the categorical label [N, d1, d2, ...]
          argmax_dim: dimension to apply
  
      Return:
          A tensor with categorical labels [N, d2, ...]
  
      Example:
          >>> x = torch.tensor([[0.2, 0.5], [0.9, 0.1]])
          >>> to_categorical(x)
          tensor([1, 0])
  
      """
      return torch.argmax(x, dim=argmax_dim)
  
imports: import sys
  from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from lightning_utilities import apply_to_collection
  from torch import Tensor
  from torchmetrics.utilities.exceptions import TorchMetricsUserWarning
  from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_12, _TORCH_GREATER_EQUAL_1_13, _XLA_AVAILABLE
  from torchmetrics.utilities.prints import rank_zero_warn
label_desc: Use image node_id 11 for calling a global function with example usage: to_categorical(x, argmax_dim) and returns: torch