def permute_vector(permutation, vector):
    """
    Returns the result of applying the given permutation to the given vector.
    Input permutation and vector should be of the same length.
    Input permutation should be an index vector (e.g. a permutation of
    the integers from 0 to dimension-1 of the vector)
    """
    return vector[permutation]