Numpy Mean Structured Array

前端 未结 4 766
孤街浪徒
孤街浪徒 2020-12-21 04:42

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

4条回答
  •  春和景丽
    2020-12-21 05:18

    A little bit faster and simpler solution based on itertools, without using view(), is

    [(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.

提交回复
热议问题