I have an array of indices, some of which are repeats, and I want to loop through all unique values and identify which instance of a given index corresponds to the highest value of an array of the same length. I have a working code for this, but to run through the hundreds of thousands (sometimes millions) of indices takes time, and I was wondering if there was a faster way. I suspect my use of np.append is the problem but I haven't come across a better way.
import numpy as np
# Randomly draw 100,000 integers between 1 and 100,000 as an example
index_list = np.random.randint(low=1, high=100000, size=100000)
# The data array being indexed
vals = np.linspace(1.,100000.,100000)
unique_index = np.unique(index_list)
biggest = []
for line in unique_index:
biggest = np.append(biggest,max(vals[np.where(index_list == line)]))