如何合并两个列表的索引? [英] How do I combine indexes of two lists?
本文介绍了如何合并两个列表的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有列表[[1,2],[3,4]]和[[5,6],[7,8]]
Let's say I have the lists [[1,2],[3,4]] and [[5,6],[7,8]]
我希望结果为[[6,8],[10,12]].
I expect [[6, 8], [10, 12]] as the result.
我正在尝试根据数字的索引对其求和.
I'm trying to sum up numbers according to their indexes.
def sum_matrix(num1, num2):
推荐答案
ndarray的另一项简单工作:
Another easy job for ndarrays:
>>> from numpy import array
>>> list1, list2 = [[1,2],[3,4]], [[5,6],[7,8]]
>>> (array(list1) + array(list2)).tolist()
[[6, 8], [10, 12]]
这篇关于如何合并两个列表的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文