def arg_maxes(arr, indices=None):
    """
    Get indices of all maximal values in array
    :param arr: the array
    :param indices: optional permutation on indices
    :return: array with indices of maxima
    """
    if len(arr) == 0:
        return []

    maxes = []
    maximum = max(arr)
    for idx, el in enumerate(arr):
        if el == maximum:
            if indices:
                maxes.append(indices[idx])
            else:
                maxes.append(idx)
    return maxes