code: def toarray(vari):
      
      if isinstance(vari, Poly):
          shape = vari.shape
          out = numpy.asarray(
              [{} for _ in range(numpy.prod(shape))],
              dtype=object
          )
          core = vari.A.copy()
          for key in core.keys():
  
              core[key] = core[key].flatten()
  
              for i in range(numpy.prod(shape)):
  
                  if not numpy.all(core[key][i] == 0):
                      out[i][key] = core[key][i]
  
          for i in range(numpy.prod(shape)):
              out[i] = Poly(out[i], vari.dim, (), vari.dtype)
  
          out = out.reshape(shape)
          return out
  
      return numpy.asarray(vari)
docs: Convert polynomial array into a numpy.asarray of polynomials.
  
      Args:
          vari (Poly, numpy.ndarray):
              Input data.
  
      Returns:
          (numpy.ndarray):
              A numpy array with ``Q.shape==A.shape``.
  
      Examples:
          >>> poly = cp.prange(3)
          >>> print(poly)
          [1, q0, q0^2]
          >>> array = cp.toarray(poly)
          >>> print(isinstance(array, numpy.ndarray))
          True
          >>> print(array[1])
          q0