code: def dimsplit(P):
      
      P = P.copy()
  
      if not chaospy.poly.caller.is_decomposed(P):
          raise TypeError("Polynomial not on component form.")
      A = []
  
      dim = P.dim
      coef = P(*(1,)*dim)
      M = coef!=0
      zero = (0,)*dim
      ones = [1]*dim
      A = [{zero: coef}]
  
      if zero in P.A:
  
          del P.A[zero]
          P.keys.remove(zero)
  
      for key in P.keys:
          P.A[key] = (P.A[key]!=0)
  
      for i in range(dim):
  
          A.append({})
          ones[i] = numpy.nan
          Q = P(*ones)
          ones[i] = 1
          if isinstance(Q, numpy.ndarray):
              continue
          Q = Q.A
  
          if zero in Q:
              del Q[zero]
  
          for key in Q:
  
              val = Q[key]
              A[-1][key] = val
  
      A = [Poly(a, dim, None, P.dtype) for a in A]
      P = Poly(A, dim, None, P.dtype)
      P = P + 1*(P(*(1,)*dim)==0)*M
  
      return P
docs: Segmentize a polynomial (on decomposed form) into it's dimensions.
  
      In array missing values are padded with 1 to make dimsplit compatible with
      ``poly.prod(Q, 0)``.
  
  
      Args:
          P (Poly):
              Input polynomial.
  
      Returns:
          (Poly):
              Segmentet polynomial array where ``Q.shape==P.shape+(P.dim+1,)``.
              The surplus element in ``P.dim+1`` is used for coefficients.
  
      Examples:
          >>> x,y = chaospy.variable(2)
          >>> P = chaospy.Poly([2, x*y, 2*x])
          >>> Q = chaospy.dimsplit(P)
          >>> print(Q)
          [[2, 1, 2], [1, q0, q0], [1, q1, 1]]
          >>> print(chaospy.prod(Q, 0))
          [2, q0q1, 2q0]