Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading