code: def get_hard_distribution(
      Y: np.ndarray, num_classes: Optional[int] = None
  ) -> np.ndarray:
      """
      Constructs the hard label distribution (one-hot encoding).
  
      Parameters
      ----------
      Y
          Prediction array. Can be soft or hard label distribution, or a label.
      num_classes
          Number of classes to be considered.
  
      Returns
      -------
      Hard label distribution (one-hot encoding).
      """
      if len(Y.shape) == 1 or (len(Y.shape) == 2 and Y.shape[1] == 1):
          if num_classes is None:
              raise ValueError(
                  "Number of classes has to be specified to transform the labels into one-hot encoding."
              )
  
          Y = Y.reshape(-1).astype(np.int32)
          Y_ohe = np.zeros((Y.shape[0], num_classes))
          Y_ohe[np.arange(Y.shape[0]), Y] = 1
          return Y_ohe
  
      if len(Y.shape) != 2:
          raise ValueError(
              f"Expected a 2D array, but the input array has a dimension of {len(Y.shape)}"
          )
  
      Y_ohe = np.zeros_like(Y)
      Y_ohe[np.arange(Y.shape[0]), np.argmax(Y, axis=1)] = 1
      return Y_ohe
  
file_path: alibi/alibi/explainers/backends/cfrl_base.py
imports: import numpy
  from typing import Callable, Any, Optional
  from abc import ABC, abstractmethod
label_desc: Use image node_id 4 for calling a global function with example usage: get_hard_distribution(Y, num_classes) and returns: Y_ohe, Y_ohe