I have a list (called ys) of three lists (ys[0], ys[1], ys[2]). Each of the three lists contains 10 arrays each of length 1534. The first list is shown below for example:
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])]
I would like to find a way to sum these arrays element by element so that I am left with one array of length 1534. The excerpt from the code that generates the list of three lists is this:
def ys(norm2, ell_T):
t=[]
e=[]
b=[]
T=norm2[0]
E=norm2[1]
B=norm2[2]
for i in range (0, len(T)):
yt=((ell_T * (ell_T+1) * T[i])/(2*pi))
ye=((ell_T * (ell_T+1) * E[i])/(2*pi))
yb=((ell_T * (ell_T+1) * B[i])/(2*pi))
t.append(yt)
e.append(ye)
b.append(yb)
return t, e, b
ys=ys(norm2, ell_T)
My attempt at the summation and a subsequent average (which doesn't work) is shown below:
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)
The problem seems to be the np.add functions. They require inputs such as np.add(ys[0][0], ys[0][1], etc...) but I want to generalise this so it isn't fixed to 10 arrays.