code: def select(data, trial=None, invert=False, **axes_to_select):
      if trial is not None and not isinstance(trial, Iterable):
          raise TypeError('Trial needs to be iterable.')
      for axis_to_select, values_to_select in axes_to_select.items():
          if (not isinstance(values_to_select, Iterable) or
             isinstance(values_to_select, str)):
              raise TypeError(axis_to_select + ' needs to be iterable.')
      if trial is None:
          trial = range(data.number_of('trial'))
      else:
          trial = trial
          if invert:
              trial = setdiff1d(range(data.number_of('trial')), trial)
      output = data._copy(axis=False)
      for one_axis in output.axis:
          output.axis[one_axis] = empty(len(trial), dtype='O')
      output.data = empty(len(trial), dtype='O')
      to_select = {}
      for cnt, i in enumerate(trial):
          lg.debug('Selection on trial {0: 6}'.format(i))
          for one_axis in output.axis:
              values = data.axis[one_axis][i]
              if one_axis in axes_to_select.keys():
                  values_to_select = axes_to_select[one_axis]
                  if len(values_to_select) == 0:
                      selected_values = ()
                  elif isinstance(values_to_select[0], str):
                      selected_values = asarray(values_to_select, dtype='U')
                  else:
                      if (values_to_select[0] is None and
                         values_to_select[1] is None):
                          bool_values = ones(len(values), dtype=bool)
                      elif values_to_select[0] is None:
                          bool_values = values < values_to_select[1]
                      elif values_to_select[1] is None:
                          bool_values = values_to_select[0] <= values
                      else:
                          bool_values = ((values_to_select[0] <= values) &
                                         (values < values_to_select[1]))
                      selected_values = values[bool_values]
                  if invert:
                      selected_values = setdiff1d(values, selected_values)
                  lg.debug('In axis {0}, selecting {1: 6} '
                           'values'.format(one_axis,
                                           len(selected_values)))
                  to_select[one_axis] = selected_values
              else:
                  lg.debug('In axis ' + one_axis + ', selecting all the '
                           'values')
                  selected_values = data.axis[one_axis][i]
              output.axis[one_axis][cnt] = selected_values
          output.data[cnt] = data(trial=i, **to_select)
      return output