code: def prob_to_index(prob, n_index):
      """Convert cumulative probability to 0-based index in the given range."""
      ele_prob = 1 / n_index
      index = int(math.floor(prob / ele_prob))
      # Can happen when `prob` is very close to 1.
      if index == n_index:
          index -= 1
      return index
  
imports: import math
  from keras_tuner import protos
label_desc: Use image node_id 3 for calling a global function with example usage: prob_to_index(prob, n_index) and returns: index