code: def _filtdim(items, shape, dim, nsl):
      
      normshape = tuple(stop - start for start, stop in shape)
      nsl_type = type(nsl)
      newitems = list()
      # Number of groups
      num = reduce(operator.mul, normshape[:dim+1])
      # Size of each group
      size = len(items) // num
      # Size of the dimension
      n = normshape[dim]
      if nsl_type is int:
          for i in range(num):
              if i % n == nsl:
                  newitems += items[size*i:size*(i+1)]
          # Collapse dimension
          newshape = shape[:dim] + shape[dim+1:]
      elif nsl_type is slice:
          for i in range(num):
              if nsl.start <= (i % n) < nsl.stop:
                  newitems += items[size*i:size*(i+1)]
          # Reshape dimension
          offset = shape[dim][0]
          redim = (offset + nsl.start, offset + nsl.stop)
          newshape = shape[:dim] + (redim, ) + shape[dim+1:]
      # farray
      else:
          if nsl.size < clog2(n):
              fstr = "expected dim {} select to have >= {} bits, got {}"
              raise ValueError(fstr.format(dim, clog2(n), nsl.size))
          groups = [list() for _ in range(n)]
          for i in range(num):
              groups[i % n] += items[size*i:size*(i+1)]
          for muxins in zip(*groups):
              it = boolfunc.iter_terms(nsl._items)
              xs = [reduce(operator.and_, (muxin, ) + next(it))
                    for muxin in muxins]
              newitems.append(reduce(operator.or_, xs))
          # Collapse dimension
          newshape = shape[:dim] + shape[dim+1:]
      return newitems, newshape
docs: Return items, shape filtered by a dimension slice.