计算多个数组中每个索引的值的平均值

时间:2019-08-18 14:14:56

标签: python numpy mean

当前,我正在寻找一种紧凑且更有效的解决方案(而不是多个嵌套的for循环)来计算给定多个numpy数组的索引值的平均值。

具体给出

[array([2.4, 3.5, 2.9]),
array([4.5, 1.8, 1.4])]

我需要计算以下数组:

[array([3.45, 2.65, 2.15])]

有什么主意吗?谢谢大家。

2 个答案:

答案 0 :(得分:1)

使用<figure> {% include code-snippets/big-test.html %} <figcaption>Bad: Three different scenarios bundled in to one test</figcaption> </figure> 仅需一行命令即可

numpy

答案 1 :(得分:0)

没有Numpy,您可以使用地图和邮政编码来获取它。

lists = [[2.4, 3.5, 2.9],[4.5, 1.8, 1.4]]

li = list(zip(*lists))
sumation = list(map(sum,li))
average = list(map( lambda x: x/len(lists) ,sumation))

print(s)