给定下面的列表数组,我希望能够创建一个新列表,给出列的平均值和标准偏差
a = [ [1, 2, 3],
[2, 3, 4],
[3, 4, 5, 6],
[1, 2],
[7, 2, 3, 4]]
所需结果
mean = 2.8, 2.6, 3.75, 5
STDEV= 2.48997992, 0.894427191, 0.957427108, 1.414213562
我发现下面的例子给出了平均值,这似乎工作得很好,但我不清楚如何适应标准偏差
import numpy as np
import numpy.ma as ma
from itertools import zip_longest
a = [ [1, 2, 3],
[2, 3, 4],
[3, 4, 5, 6],
[1, 2],
[7, 2, 3, 4]]
averages = [np.ma.average(ma.masked_values(temp_list, None)) for temp_list in zip_longest(*a)]
print(averages)