def all_knots(beta):
    """
    Find all the knots of constant pieces in beta. Every knot is represented by the right index of it.
    Always include the knot at 0 and at len(beta)).
    @param beta np.array(p, ): the vector to find knots.
    @return List[int]: a list of indices.
    """
    knots_list = []
    for i in range(1, len(beta)):
        if beta[i-1] < beta[i]: knots_list.append(i)
    return [0] + knots_list + [len(beta)]