code: def to_categorical(
      labels: Union[np.ndarray, List[float]],
      nb_classes: Optional[int] = None,
  ) -> np.ndarray:
      """
      Convert an array of labels to binary class matrix.
  
      :param labels: An array of integer labels of shape `(nb_samples,)`.
      :param nb_classes: The number of classes (possible labels).
      :return: A binary matrix representation of `y` in the shape `(nb_samples, nb_classes)`.
      """
      labels = np.array(labels, dtype=int)
      if nb_classes is None:
          nb_classes = np.max(labels) + 1
      categorical = np.zeros(
          (labels.shape[0], nb_classes), dtype=np.float32
      )
      categorical[np.arange(labels.shape[0]), np.squeeze(labels)] = 1
      return categorical
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import math
  import os
  import shutil
  import sys
  import tarfile
  import warnings
  import zipfile
  from functools import wraps
  from inspect import signature
  from typing import TYPE_CHECKING, Callable, List, Dict, Optional, Tuple, Union
  import numpy
  import six
  from scipy.special import gammainc
  from tqdm.auto import tqdm
  from art import config
label_desc: Use image node_id 10 for calling a global function with example usage: to_categorical(labels, nb_classes) and returns: categorical