code: def class_weight_to_sample_weights(y, class_weight):
      sample_weight = np.ones(
          shape=(y.shape[0],), dtype=backend.floatx()
      )
      if len(y.shape) > 1:
          if y.shape[-1] != 1:
              y = np.argmax(y, axis=-1)
          else:
              y = np.squeeze(y, axis=-1)
      y = np.round(y).astype("int32")
      for i in range(y.shape[0]):
          sample_weight[i] = class_weight.get(int(y[i]), 1.0)
      return sample_weight
  
file_path: keras/keras/trainers/data_adapters/data_adapter_utils.py
imports: import math
  import numpy
  import tree
  from keras import backend
  from keras.api_export import keras_export
label_desc: Use image node_id 7 for calling a global function with example usage: class_weight_to_sample_weights(y, class_weight) and returns: sample_weight