按元素添加 2 個列表? - Element-wise addition of 2 lists?

問題:

I have now:我現在有了:

list1 = [1, 2, 3]
list2 = [4, 5, 6]

I wish to have:我希望有:

[1, 2, 3]
 +  +  +
[4, 5, 6]
|| || ||
[5, 7, 9]

Simply an element-wise addition of two lists.簡單地將兩個列表按元素相加。

I can surely iterate the two lists, but I don't want do that.我當然可以迭代這兩個列表,但我不想這樣做。

What is the most Pythonic way of doing so?這樣的最 Pythonic 的方式是什麼?


解決方案:

參考一: https://stackoom.com/question/1GWBl
參考二: Element-wise addition of 2 lists?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章