def sorted_perm(a, label=None, reverse=False):
    """ return sorted $a and the induced permutation.
        Inplace operation """
    # np.asarray applied this tuple lead to error, if label is string
    # because a should be used as elementwise comparison
    if label is None:
        label = np.arange(a.shape[0])
    hist, label = zip(*sorted(zip(a, label), reverse=reverse))
    hist = np.asarray(hist)
    label = np.asarray(label)
    return hist, label