<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fit_quadrature(orth, nodes, weights, solves, retall=False, norms=None, **kws):
 """ Using spectral projection to create a polynomial approximation over distribution space. Args: orth (chaospy.poly.base.Poly):
 Orthogonal polynomial expansion. Must be orthogonal for the approximation to be accurate. nodes (numpy.ndarray):
 Where to evaluate the polynomial expansion and model to approximate. ``nodes.shape==(D,K)`` where ``D`` is the number of dimensions and ``K`` is the number of nodes. weights (numpy.ndarray):
 Weights when doing numerical integration. ``weights.shape == (K,)`` must hold. solves (numpy.ndarray):
 The model evaluation to approximate. If `numpy.ndarray` is provided, it must have ``len(solves) == K``. If callable, it must take a single argument X with ``len(X) == D``, and return a consistent numpy compatible shape. norms (numpy.ndarray):
 In the of TTR using coefficients to estimate the polynomial norm is more stable than manual calculation. Calculated using quadrature if no provided. ``norms.shape == (len(orth),)`` must hold. Returns: (chaospy.poly.base.Poly):
 Fitted model approximation in the form of an polynomial. """

    orth = chaospy.poly.Poly(orth)
    nodes = numpy.asfarray(nodes)
    weights = numpy.asfarray(weights)

    if callable(solves):
        solves = [solves(node) for node in nodes.T]
    solves = numpy.asfarray(solves)

    shape = solves.shape
    solves = solves.reshape(weights.size, int(solves.size/weights.size))

    ovals = orth(*nodes)
    vals1 = [(val*solves.T*weights).T for val in ovals]

    if norms is None:
        norms = numpy.sum(ovals**2*weights, -1)
    else:
        norms = numpy.array(norms).flatten()
        assert len(norms) == len(orth)

    coefs = (numpy.sum(vals1, 1).T/norms).T
    coefs = coefs.reshape(len(coefs), *shape[1:])
    approx_model = chaospy.poly.transpose(chaospy.poly.sum(orth*coefs.T, -1))

    if retall:
        return approx_model, coefs
    return approx_model