def report_best_and_last(x: np.ndarray, lower_the_better: bool = True):
  """Finds the best and the last result of an experiment."""
  #  In format [exp_str(step), metric1, metric2, ...]
  assert lower_the_better
  all_training_steps = get_model_steps(x)
  if all_training_steps is not None:
    x = x[np.argsort(all_training_steps)]
  ds = np.copy(x[:, 1:])
  last_results = []
  for j in range(ds.shape[1]):
    last_nonzero_rowid = np.nonzero(ds[:, j])[0]
    if len(last_nonzero_rowid) != 0:  # pylint: disable=g-explicit-length-test
      last_results.append(ds[np.max(last_nonzero_rowid), j])
    else:
      last_results.append(np.inf)
  ds[np.where(ds == 0)] = np.inf
  best_results = []
  for j in range(ds.shape[1]):
    best_results.append(ds[np.nanargmin(ds[:, j]), j])
  return dict(last=last_results, best=best_results)
Finds the best and the last result of an experiment.
videogvt/interfaces/colab_utils.py