def permute(arr, permutation):
    """ Permute the array: permutation[i] is the new index for the i-th element of arr """
    if permutation is None:
        permutation = range(len(arr))
    result = [None] * len(arr)
    for element, index in zip(arr, permutation):
        result[index] = element
    return result