code: def sort_by_field(boxlist, field, order=SortOrder.DESCEND):
      """Sort boxes and associated fields according to a scalar field.
  
      A common use case is reordering the boxes according to descending scores.
  
      Args:
        boxlist: BoxList holding N boxes.
        field: A BoxList field for sorting and reordering the BoxList.
        order: (Optional) 'descend' or 'ascend'. Default is descend.
  
      Returns:
        sorted_boxlist: A sorted BoxList with the field in the specified order.
  
      Raises:
        ValueError: if specified field does not exist or is not of single dimension.
        ValueError: if the order is not either descend or ascend.
      """
      if not boxlist.has_field(field):
          raise ValueError("Field " + field + " does not exist")
      if len(boxlist.get_field(field).shape) != 1:
          raise ValueError(
              "Field " + field + "should be single dimension."
          )
      if order != SortOrder.DESCEND and order != SortOrder.ASCEND:
          raise ValueError("Invalid sort order")
  
      field_to_sort = boxlist.get_field(field)
      sorted_indices = np.argsort(field_to_sort)
      if order == SortOrder.DESCEND:
          sorted_indices = sorted_indices[::-1]
      return gather(boxlist, sorted_indices)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import numpy
  from .None import np_box_list, np_box_ops
label_desc: Use image node_id 6 for calling a global function with example usage: sort_by_field(boxlist, field, order) and returns: gather