def vector_to_dictionary(vector, layers):
    """
    Convert the parameter vector of a model into a dictionary used by the model

    Arguments:
    vector      -- one-dimensional vector in orders: "W1", "W2", "WL", "b1", "b2", "bL"
    layers      -- list of (n_uints, activations) pairs that define network structure, including input layer X

    Returns:
    ret -- parameter dictionary, {"W1": ..., "WL": ..., "b1": ..., "bL": ..., "r1": ..., "rL": ...}
    """

    ret = {}
    idx = 0

    # recover Ws first
    for l in range(1, len(layers)):
        length = layers[l][0] * layers[l - 1][0]
        ret["W" + str(l)] = vector[idx:idx + length].copy().reshape(
            (layers[l][0], layers[l - 1][0]))
        idx = idx + length

    # recover bs
    for l in range(1, len(layers)):
        length = layers[l][0]
        ret["b" + str(l)] = vector[idx:idx + length].copy().reshape(
            (layers[l][0], 1))
        idx = idx + length

    # recover rs
    for l in range(1, len(layers)):
        length = layers[l][0]
        ret["r" + str(l)] = vector[idx:idx + length].copy().reshape(
            (layers[l][0], 1))
        idx = idx + length

    return ret