本文介绍了如何对 N 个列表的元素求和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
谁能给我一个提示如何聚合(总结)多个列表的特定元素?
can anybody please give me a hint how to aggregate (sum up) specific elements of multiple lists?
例如,我有 20 个名称模式相似的列表,每个列表代表相应家庭(代理)随时间推移的消费支出(即索引):
For example I have 20 lists with a similar name pattern, each representing consumption spending over time (i.e. index) of the corresponding household (agent):
我需要类似 value = sum of index what's in c_agent_*[whatever]
I need something like value = sum of index whatever's in c_agent_*[whatever]
推荐答案
使用 zip 将列表组合"成一个,然后对每个索引的元素求和:
Use zip to "combine" lists into single one, then sum elements for each index:
打印
这篇关于如何对 N 个列表的元素求和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!