code: def find_best_step(err_vals):
      
      if np.all(np.isnan(err_vals)):
          raise ValueError('All err_vals are nans!')
      return np.nanargmin(err_vals)
docs: Returns the index of the lowest of the passed values. Catches nans etc.