How to invert a permutation array in numpy
Short answer def invert_permutation(p): “””Return an array s with which np.array_equal(arr[p][s], arr) is True. The array_like argument p must be some permutation of 0, 1, …, len(p)-1. “”” p = np.asanyarray(p) # in case p is a tuple, etc. s = np.empty_like(p) s[p] = np.arange(p.size) return s Sorting is an overkill here. This is just … Read more