记录的百分位数和中位数方法适用于未处理的原始数据:
raw_data = [1,1,1,1,2,3,4,4,5,5] # observations
a = np.array(raw_data)
np.median(a)
a = np.array(raw_data)
np.percentile(a, 50)
如何使用下面的summarized_data
获得相同的结果(不首先扩展):
summarised_data = [[1,4],[2,1],[3,1],[4,2],[5,2]] # [[observation, number_of_responses], [...]]
即,不执行相应的:
data = [n for i in range(len(summarised_data)) for n in [summarised_data[i][0]] * summarised_data[i][1]]