Suppose that I have a structured array of students (strings) and test scores (ints), where each entry is the score that a specific student received on a specific test. Each
A little bit faster and simpler solution based on itertools, without using view(), is
itertools
[(k,e['score'][list(g)].mean()) for k, g in groupby(argsort(e),e['student'].__getitem__ )]
This is the same idea of ecatmur, but works in terms of indices employing argsort() instead of sort.