简体   繁体   中英

Summation of 4 lists gives me a list with lists instead of summing there elements

I am trying to sum from 4 lists there elements with each other. For a example the first element from fours lists, then the second element etc

But instead of that i am getting a list with nested lists with the four elements and i cannot understand why and how to solve it.Any ideas?

#dependency influence calculation
def dep_Influence(a,b,c,d,decimal):
    influence=[]
    for i in range(len(a)):
       x=float(a[i])+0,5*float(b[i])+0,33*float(c[i])+0,25*float(d[i])
       influence.append(x)
    influence = np.around(influence,decimal)
    return influence

When multiplying by float numbers, use points instead of commas to represent those values:

def dep_Influence(a,b,c,d,decimal):
    influence=[]
    for i in range(len(a)):
       x=float(a[i])+0.5*float(b[i])+0.33*float(c[i])+0.25*float(d[i])
       influence.append(x)
    influence = np.around(influence,decimal)
    return influence
print(dep_Influence([1, 2, 3], [1, 2, 3],  [1, 2, 3], [1, 2, 3], 2))

[2.08 4.16 6.24]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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