code: def basis(start, stop=None, dim=1, sort="G", cross_truncation=1.):
      if stop is None:
          start, stop = numpy.array(0), start
      start = numpy.array(start, dtype=int)
      stop = numpy.array(stop, dtype=int)
      dim = max(start.size, stop.size, dim)
      indices = numpy.array(chaospy.bertran.bindex(
          numpy.min(start), 2*numpy.max(stop), dim, sort, cross_truncation))
      if start.size == 1:
          bellow = numpy.sum(indices, -1) >= start
      else:
          start = numpy.ones(dim, dtype=int)*start
          bellow = numpy.all(indices-start >= 0, -1)
      if stop.size == 1:
          above = numpy.sum(indices, -1) <= stop.item()
      else:
          stop = numpy.ones(dim, dtype=int)*stop
          above = numpy.all(stop-indices >= 0, -1)
      pool = list(indices[above*bellow])
      arg = numpy.zeros(len(pool), dtype=int)
      arg[0] = 1
      poly = {}
      for idx in pool:
          idx = tuple(idx)
          poly[idx] = arg
          arg = numpy.roll(arg, 1)
      x = numpy.zeros(len(pool), dtype=int)
      x[0] = 1
      A = {}
      for I in pool:
          I = tuple(I)
          A[I] = x
          x = numpy.roll(x,1)
      return Poly(A, dim)