内容简介:翻译自:https://stackoverflow.com/questions/19261747/sum-of-n-lists-element-wise-python
中N个列表的元素总和?我知道如果我们定义了n个列表(调用第i个列表c_i),我们可以这样做:
z = [sum(x) for x in zip(c_1, c_2, ...)]
例如:
c1 = [1,2] c2 = [3,4] c3 = [5,6] z = [sum(x) for x in zip(c1,c2,c3)]
这里z = [9,12]
但是如果我们没有定义c_i而在列表C中有c_1 … c_n呢?
如果我们只有C,是否有类似的方法来找到z?
我希望这很清楚.
已解决:我想知道*操作符的全部内容……谢谢!
[sum(x) for x in zip(*C)]
在上面,C是c_1 … c_n的列表.正如评论中的 link 所述(谢谢,@ kevinsa5!):
*
is the “splat” operator: It takes a list as input, and expands it into actual positional arguments in the function call.
有关其他详细信息,请查看 documentation ,在“解压参数列表”下,并阅读有关 calls (谢谢,@ abarnert!)
翻译自:https://stackoverflow.com/questions/19261747/sum-of-n-lists-element-wise-python
以上所述就是小编给大家介绍的《N的总和列出了元素方式的python》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- php – 使用除以总和的正确总和,抵消舍入误差
- c# – 如何使用XAML在WPF中列出颜色?
- JDK 12 早期试用版发布,尚未列出具体更新内容
- LeetCode39.组合总和 JavaScript
- LeetCode - 112 - 路径总和(path-sum)
- 在RHEL和CentOS上检查或列出已安装的安全更新的两种方法
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Developing Large Web Applications
Kyle Loudon / Yahoo Press / 2010-3-15 / USD 34.99
As web applications grow, so do the challenges. These applications need to live up to demanding performance requirements, and be reliable around the clock every day of the year. And they need to withs......一起来看看 《Developing Large Web Applications》 这本书的介绍吧!