我有一个由三个列表组成的列表(ys[0]、ys[1]、ys[2])。三个列表中的每一个都包含10个长度为1534的数组。第一个列表如下所示:In [57]: print ys[0]
[array([ 1655.13816505, 1547.98589715, 572.2745519 , ..., 89.10781318,
93.89836665, 95.07931966]), array([ 1222.2549591 , 375.13612313, 1117.62684517, ..., 92.01444874,
96.37158146, 98.09804547]), array([ 405.61715294, 347.45411 , 458.31631866, ..., 95.87440348,
92.59379305, 96.88934008]), array([ 958.5300296 , 690.68863703, 1315.69537196, ..., 96.02464434,
94.58280479, 93.77347022]), array([ 276.97463055, 457.34617477, 908.78859867, ..., 94.75916652,
94.02373941, 94.15538106]), array([ 1822.50632297, 596.38771818, 1163.05119636, ..., 90.92428715,
97.46551579, 90.34230747]), array([ 1609.11576638, 1343.19751488, 891.16993616, ..., 94.081789 ,
91.84201144, 94.06961381]), array([ 1481.02653876, 843.39342494, 1208.37885821, ..., 95.86349883,
95.93122661, 92.94565202]), array([ 1330.1940189 , 844.70910408, 1151.75233836, ..., 98.82465514,
100.37876234, 96.15178672]), array([ 1287.56325832, 365.89812057, 1034.15108853, ..., 90.64446465,
94.99436954, 90.88272168])]
我想找到一种方法,将这些数组逐个元素相加,这样就只剩下一个长度为1534的数组。生成三个列表列表的代码摘录如下:
^{pr2}$
我的求和和和后一个平均值的尝试如下所示:def averageys(ys, theory):
t=[]
e=[]
b=[]
for i in range(1, len(ys[0])):
yst_arrays=ys[0][i]
yse_arrays=ys[1][i]
ysb_arrays=ys[2][i]
sumT=np.add(yst_arrays)
sumE=np.add(yse_arrays)
sumB=np.add(ysb_arrays)
avt=sumT/len(ys[0])
ave=sumE/len(ys[0])
avb=sumB/len(ys[0])
t.append(avt)
e.append(ave)
b.append(avb)
return t, e, b
averageys=averageys(ys, theory)
问题似乎是np.添加功能。它们需要输入,例如np.添加(ys[0][0],ys[0][1]等),但我想概括一下,这样就不会固定到10个数组。在