def decode_fit_par(fit_par, constraint_types):
    """
    Translate the 1D array of fit parameters to individual lists.

    The fit paramters are sorted into the lists segment_borders, y_at_borders
    slope_at_borders based on the strings given in constraint_types. The three
    lists are used as arguments in piecewise_polynomial_fit called in the
    functions sum_of_squared_residuals and segment_regression.

    Parameters
    ----------
    fit_par : ndarray
        A 1D array containing the fit parameters. Contains segment_borders,
        and possibly y_at_borders and slope at borders directly following the
        corresponding segment border.
    constraint_types : list of str
        Encodes which value in fit_par is which kind of constraint. 'b' means
        segmentation border, 'y' means a common y value of adjacent segments,
        and 's' means a common slope of adjacent segments.

    Returns
    -------
    segment_borders, y_at_borders, slope_at_borders
        The arguments used for piecewise_polynomial_fit, see its docstring for
        details.

    """
    # Fit parameters from segment_regression and sum_of_squared_residuals are
    # reordered to be understood by piecewise_polynomial_fit.
    segment_borders = []
    y_at_borders = []
    slope_at_borders = []
    for idx, curr_type in enumerate(constraint_types):
        if curr_type == 'b':
            segment_borders.append(fit_par[idx])
            y_at_borders.append(None)
            slope_at_borders.append(None)
        if curr_type == 'y':
            y_at_borders[-1] = fit_par[idx]
        if curr_type == 's':
            slope_at_borders[-1] = fit_par[idx]

    return (segment_borders, y_at_borders, slope_at_borders)