text: import numpy as np
  
  def max_lt(seq, val):
      """
      Return greatest item in seq for which item < val applies.
      None is returned if seq was empty or all items in seq were >= val.
      """
      max = 0
      idx = len(seq) - 1
      while idx >= 0:
          if seq[idx] < val and seq[idx] >= 0 and seq[idx] > max:
              max = seq[idx]
          idx -= 1
      return max
  
  
  def min_gt(seq, val):
      """
      Return smallest item in seq for which item > val applies.
      None is returned if seq was empty or all items in seq were >= val.
      """
      min = np.inf
      idx = len(seq) - 1
      while idx >= 0:
          if seq[idx] >= val and seq[idx] < min:
              min = seq[idx]
          idx -= 1
      return min
  
  
  def norm_obs_clip(obs, clip_min=-1, clip_max=1, fixed_radius=0, normalize_to_range=False):
      """
      This function returns the difference between min and max value of an observation
      :param obs: Observation that should be normalized
      :param clip_min: min value where observation will be clipped
      :param clip_max: max value where observation will be clipped
      :return: returnes normalized and clipped observatoin
      """
      if fixed_radius > 0:
          max_obs = fixed_radius
      else:
          max_obs = max(1, max_lt(obs, 1000)) + 1
  
      min_obs = 0  # min(max_obs, min_gt(obs, 0))
      if normalize_to_range:
          min_obs = min_gt(obs, 0)
      if min_obs > max_obs:
          min_obs = max_obs
      if max_obs == min_obs:
          return np.clip(np.array(obs) / max_obs, clip_min, clip_max)
      norm = np.abs(max_obs - min_obs)
      return np.clip((np.array(obs) - min_obs) / norm, clip_min, clip_max)
  