code: def quantize_events(events, fps, length=None, shift=None):
      """
      Quantize the events with the given resolution.
  
      Parameters
      ----------
      events : list or numpy array
          Events to be quantized.
      fps : float
          Quantize with `fps` frames per second.
      length : int, optional
          Length of the returned array. If 'None', the length will be set
          according to the latest event.
      shift : float, optional
          Shift the events by `shift` seconds before quantization.
  
      Returns
      -------
      numpy array
          Quantized 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.")
      # shift all events if needed
      if shift is not None:
          import warnings
  
          warnings.warn(
              "`shift` parameter is deprecated as of version 0.16 and "
              "will be removed in version 0.18. Please shift the "
              "events manually before calling this function."
          )
          events += shift
      # determine the length for the quantized array
      if length is None:
          # set the length to be long enough to cover all events
          length = int(round(np.max(events) * float(fps))) + 1
      else:
          # else filter all events which do not fit in the array
          # since we apply rounding later, we need to subtract half a bin
          events = events[
              : np.searchsorted(events, float(length - 0.5) / fps)
          ]
      # init array
      quantized = np.zeros(length)
      # quantize
      events *= fps
      # indices to be set in the quantized array
      idx = np.unique(np.round(events).astype(int))
      quantized[idx] = 1
      # return the quantized array
      return quantized
  
imports: from __future__ import absolute_import, division, print_function
  import argparse
  import contextlib
  import io
  import numpy
label_desc: Use image node_id 8 for calling a global function with example usage: quantize_events(events, fps, length, shift) and returns: quantized