code: def sup_inf(u):
      
  
      if np.ndim(u) == 2:
          P = _P2
      elif np.ndim(u) == 3:
          P = _P3
      else:
          raise ValueError("u has an invalid number of dimensions "
                           "(should be 2 or 3)")
  
      erosions = []
      for P_i in P:
          erosions.append(ndi.binary_erosion(u, P_i))
  
      return np.array(erosions, dtype=np.int8).max(0)
docs: SI operator.