code: def combine_events(events, delta, combine="mean"):
      """
      Combine all events within a certain range.
  
      Parameters
      ----------
      events : list or numpy array
          Events to be combined.
      delta : float
          Combination delta. All events within this `delta` are combined.
      combine : {'mean', 'left', 'right'}
          How to combine two adjacent events:
  
              - 'mean': replace by the mean of the two events
              - 'left': replace by the left of the two events
              - 'right': replace by the right of the two events
  
      Returns
      -------
      numpy array
          Combined events.
  
      """
      # add a small value to delta, otherwise we end up in floating point hell
      delta += 1e-12
      # return immediately if possible
      if len(events) <= 1:
          return events
      # convert to numpy array or create a copy if needed
      events = np.array(events, dtype=float)
      # can handle only 1D events
      if events.ndim > 1:
          raise ValueError("only 1-dimensional events supported.")
      # set start position
      idx = 0
      # get first event
      left = events[idx]
      # iterate over all remaining events
      for right in events[1:]:
          if right - left <= delta:
              # combine the two events
              if combine == "mean":
                  left = events[idx] = 0.5 * (right + left)
              elif combine == "left":
                  left = events[idx] = left
              elif combine == "right":
                  left = events[idx] = right
              else:
                  raise ValueError(
                      "don't know how to combine two events with "
                      "%s" % combine
                  )
          else:
              # move forward
              idx += 1
              left = events[idx] = right
      # return the combined events
      return events[: idx + 1]
  
imports: from __future__ import absolute_import, division, print_function
  import argparse
  import contextlib
  import io
  import numpy
label_desc: Use image node_id 7 for calling a global function with example usage: combine_events(events, delta, combine) and returns: events, events