code: def olindex(order, dim):
      
      idxm = [0]*dim
      out = []
  
      def _olindex(idx):
          """Recursive backend for olindex."""
          if numpy.sum(idxm) == order:
              out.append(idxm[:])
              return
  
          if idx == dim:
              return
  
          idxm_sum = numpy.sum(idxm)
          idx_saved = idxm[idx]
  
          for idxi in range(order - numpy.sum(idxm) + 1):
  
              idxm[idx] = idxi
  
              if idxm_sum < order:
                  _olindex(idx+1)
  
              else:
                  break
          idxm[idx] = idx_saved
  
      _olindex(0)
      return numpy.array(out)
docs: Create an lexiographical sorted basis for a given order.
  
      Examples
      --------
      >>> chaospy.bertran.olindex(3, 2)
      array([[0, 3],
             [1, 2],
             [2, 1],
             [3, 0]])