简体   繁体   English

每个数字的列表中 arrays 的平均列表

[英]average list of arrays within a list for each number

How to average this 2 list consists of array and list, i mean to get average on each number?如何平均这两个列表由数组和列表组成,我的意思是对每个数字求平均值?

I tried below: c = (a + b)/2 but results in error 'unsupported operand types'我在下面尝试: c = (a + b)/2 但导致错误“不支持的操作数类型”

Please help me in acheiving this like the expected output below请帮助我实现这一点,就像下面预期的 output

a
[array([2.945202e-02, -5.945202e-02, 7.9454265e-03],dtype=float32),
array([2.945202e-02, -5.945202e-02, 1.9454265e-03],dtype=float32),
array([2.945202e-02, -5.945202e-02, 7.9454265e-03],dtype=float32)]

b
[array([4.945202e-02, 5.945202e-02, 5.9454265e-03],dtype=float32),
array([5.945202e-02, -7.945202e-02, 6.9454265e-03],dtype=float32),
array([6.945202e-02, -8.945202e-02, 7.9454265e-03],dtype=float32)]

Expected output average sample format on each number (Not the right answer of above average):每个数字的预期 output 平均样本格式(不是上述平均值的正确答案):

c
[array([1.945202e-02, 2.945202e-02, 2.9454265e-03],dtype=float32),
array([5.945202e-02, -4.945202e-02, 6.9454265e-03],dtype=float32),
array([6.945202e-02, -5.945202e-02, 7.9454265e-03],dtype=float32)]

If you want to find the average of a and b , you can zip a and b and iterate over the pairs of arrays and find the average of each:如果你想找到ab的平均值,你可以zip ab并遍历 arrays 对并找到每个的平均值:

avg = [(i+j)/2 for i,j in zip(a,b)]

Output: Output:

[array([0.03945202, 0.        , 0.00694543], dtype=float32),
 array([ 0.04445202, -0.06945202,  0.00444543], dtype=float32),
 array([ 0.04945202, -0.07445202,  0.00794543], dtype=float32)]

or find the average using np.mean :或使用np.mean找到平均值:

avg = np.mean([a, b], axis=0)

Output: Output:

array([[ 0.03945202,  0.        ,  0.00694543],
       [ 0.04445202, -0.06945202,  0.00444543],
       [ 0.04945202, -0.07445202,  0.00794543]], dtype=float32)

But these answers don't match the expected output.但这些答案与预期的 output 不符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM