I’m trying to add two lists element-wise in Python, but I’m not sure what the best way to do it is. Can anyone help me with this?
Here’s what I’ve tried so far:
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = list1 + list2
However, this just concatenates the two lists together, resulting in [1, 2, 3, 4, 5, 6]
.
I want to get the result [5, 7, 9]
, which is the element-wise sum of list1
and list2
.
Can anyone suggest a simple and efficient way to achieve this?
Thank you in advance for your help!