<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def toarray(vari):
 """ 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: [1, q0, q0^2] True q0 """

    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)