code: def isoutside(coords, shape):
      r
      # Label external pores for trimming below
      if len(shape) == 1:  # Spherical
          # Find external points
          r = sp.sqrt(sp.sum(coords**2, axis=1))
          Ps = r > shape[0]
      elif len(shape) == 2:  # Cylindrical
          # Find external pores outside radius
          r = sp.sqrt(sp.sum(coords[:, [0, 1]]**2, axis=1))
          Ps = r > shape[0]
          # Find external pores above and below cylinder
          if shape[1] > 0:
              Ps = Ps + (coords[:, 2] > shape[1])
              Ps = Ps + (coords[:, 2] < 0)
          else:
              pass
      elif len(shape) == 3:  # Rectilinear
          shape = sp.array(shape, dtype=float)
          try:
              lo_lim = shape[:, 0]
              hi_lim = shape[:, 1]
          except IndexError:
              lo_lim = sp.array([0, 0, 0])
              hi_lim = shape
          Ps1 = sp.any(coords > hi_lim, axis=1)
          Ps2 = sp.any(coords < lo_lim, axis=1)
          Ps = Ps1 + Ps2
      return Ps
docs: r"""
      Identifies points that lie outside the specified region.
  
      Parameters
      ----------
      domain_size : array_like
          The size and shape of the domain beyond which points should be
          trimmed. The argument is treated as follows:
  
          **sphere** : If a scalar or single element list is received, it's
          treated as the radius [r] of a sphere centered on [0, 0, 0].
  
          **cylinder** : If a two-element list is received it's treated as
          the radius and height of a cylinder [r, z] whose central axis
          starts at [0, 0, 0] and extends in the positive z-direction.
  
          **rectangle** : If a three element list is received, it's treated
          as the outer corner of rectangle [x, y, z] whose opposite corner
          lies at [0, 0, 0].
  
      Returns
      -------
      An Np-long mask of True values indicating pores that lie outside the
      domain.