code: def clip_noise_rates(noise_matrix) -> np.ndarray:
      """Clip all noise rates to proper range [0,1), but
      do not modify the diagonal terms because they are not
      noise rates.
  
      ASSUMES noise_matrix columns sum to 1.
  
      Parameters
      ----------
      noise_matrix : np.ndarray of shape (K, K), K = number of classes
          A conditional probability matrix containing the fraction of
          examples in every class, labeled as every other class.
          Diagonal terms are not noise rates, but are consistency P(label=k|true_label=k)
          Assumes columns of noise_matrix sum to 1"""
  
      def clip_noise_rate_range(noise_rate) -> float:
          """Clip noise rate P(label=k'|true_label=k) or P(true_label=k|label=k')
          into proper range [0,1)"""
          return min(max(noise_rate, 0.0), 0.9999)
  
      # Vectorize clip_noise_rate_range for efficiency with np.ndarrays.
      vectorized_clip = np.vectorize(clip_noise_rate_range)
  
      # Preserve because diagonal entries are not noise rates.
      diagonal = np.diagonal(noise_matrix)
  
      # Clip all noise rates (efficiently).
      noise_matrix = vectorized_clip(noise_matrix)
  
      # Put unmodified diagonal back.
      np.fill_diagonal(noise_matrix, diagonal)
  
      # Re-normalized noise_matrix so that columns sum to one.
      noise_matrix = noise_matrix / np.clip(
          noise_matrix.sum(axis=0), a_min=TINY_VALUE, a_max=None
      )
      return noise_matrix
  
imports: import warnings
  import numpy
  import pandas
  from typing import Union, Tuple
  from cleanlab.typing import DatasetLike, LabelLike
  from cleanlab.internal.validation import labels_to_array
  from cleanlab.internal.constants import FLOATING_POINT_COMPARISON, TINY_VALUE
label_desc: Use image node_id 2 for calling a global function with example usage: clip_noise_rates(noise_matrix) and returns: noise_matrix, min