Sometimes, we want to do element-wise addition of 2 lists with Python
In this article, we’ll look at how to do element-wise addition of 2 lists with Python.
How to do element-wise addition of 2 lists with Python?
To do element-wise addition of 2 lists with Python, we can use the map
function.
For instance, we write
from operator import add
l = list(map(add, list1, list2))
to call map
with the add
operator and the 2 lists that we want to do element-wise addition on.
And then we convert the iterable returned from map
to a list with list
.
Conclusion
To do element-wise addition of 2 lists with Python, we can use the map
function.