4个列表的求和为我提供了一个列表,而不是总结其中的元素

发布于 2025-02-13 12:32:49 字数 400 浏览 1 评论 0原文

我正在尝试从彼此之间的4个列表中总结。例如,第一个列表中的第一个元素,然后是第二个元素等,

但是我没有得到一个带有四个元素的嵌套列表,我不明白为什么以及如何求解它。

#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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥琐帝 2025-02-20 12:32:49

当乘以浮点数时,使用点代替逗号来表示这些值:

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]

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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文