<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def reduced_to_matrix(shape, degree, vals_by_weight):
 r"""Converts a reduced values dictionary into a matrix. .. note:: This is a helper used only by :func:`_specialize_surface`. The ``vals_by_weight`` mapping has keys of the form: to the number of times the first set of barycentric weights was used in the reduction process, and similarly for ``1`` and ``2``. These points correspond to barycentric weights in their own right. For example ``(0, 0, 0, 1, 2, 2)`` corresponds to the barycentric weight :math:`\left(\frac{3}{6}, \frac{1}{6}, \frac{2}{6}\right)`. Once the keys in ``vals_by_weight`` have been converted to barycentric coordinates, we order them according to our rule (bottom to top, left to right) and then return them in a single matrix. Args: shape (tuple):
 The shape of the result matrix. degree (int):
 The degree of the surface. vals_by_weight (Mapping[tuple, numpy.ndarray]):
 Dictionary of reduced nodes according to blending of each of the three sets of weights in a reduction. Returns: numpy.ndarray: The newly created reduced control points. """

    result = np.empty(shape, order="F")
    index = 0
    for k in six.moves.xrange(degree + 1):
        for j in six.moves.xrange(degree + 1 - k):
            i = degree - j - k
            key = (0,) * i + (1,) * j + (2,) * k
            result[:, index] = vals_by_weight[key][:, 0]
            index += 1
    return result