code: def generate_filter(mask):
      """generate a data filter from a data masking function
  
      mask: masking function (built with generate_mask) or a boolean mask
  
      returns a function that filters (x,y) or a monitor, based on the given mask
      x',y' = filter(x,y), where filter removes values where mask is False
  
      Examples:
        >>> mon = Monitor()
        >>> mon([0.0,0.5,1.0],2)
        >>> mon([2.0,3.0,4.0],3)
        >>> mon([4.0,5.0,6.0],4)
        >>> mon([5.0,5.5,6.5],6)
        >>>
        >>> @impose_bounds((0,5))
        ... def inputs(x):
        ...   return x
        ...
        >>> m = generate_filter(generate_mask(inputs))(mon)
        >>> m._x
        [[0.0, 0.5, 1.0], [2.0, 3.0, 4.0]]
        >>> m._y
        [2, 3]
        >>>
        >>> @integers()
        ... def identity(x):
        ...   return x
        ...
        >>> m = generate_filter(generate_mask(identity))(mon)
        >>> m._x
        [[2.0, 3.0, 4.0], [4.0, 5.0, 6.0]]
        >>> m._y
        [3, 4]
      """
  
      def func(x, z=None):
          if not hasattr(mask, "__call__"):
              _mask = mask
          else:
              _mask = mask(x, z)
          if z is None and hasattr(x, "_x") and hasattr(x, "_y"):
              from copy import copy
  
              m = copy(x)
              mon = True
          else:
              from mystic.monitors import Monitor
  
              m = Monitor()
              m._x, m._y = x, z
              mon = False
          ax = True if hasattr(m._x, "tolist") else False
          ay = True if hasattr(m._y, "tolist") else False
          from numpy import asarray
  
          m._x = asarray(m._x)[_mask]
          m._y = asarray(m._y)[_mask]
          if not ax:
              m._x = m._x.tolist()
          if not ay:
              m._y = m._y.tolist()
          if mon:
              try:
                  ai = True if hasattr(m._id, "tolist") else False
                  m._id = array(m._id)[_mask]
                  if not ai:
                      m._id = m._id.tolist()
              except IndexError:
                  pass  # XXX: m._id = []
              return m
          return m._x, m._y
  
      return func
  
label_desc: Use image node_id 5 for calling a global function with example usage: generate_filter(mask) and returns: func, m,  m, m