I have a numpy array and I want to invert it in a sense that I want to swap max and min, second max and second min and so on.
arr = [1, 2, 1, 3, 2, 4, 1, 4]
# Output should be [4, 3, 4, 2, 3, 1, 4, 1]
arr = [4, 4, 1, 2]
# Output should be [1, 1, 4, 2]
Is there a way to vectorize this?