I checked similar problem at sum of N lists element-wise python
but mine is a little bit more complicate cause I am adding list of list with another list of list
my list looks like it below
[[0 0.014285714 0.035600016]
,[0.014285714 0 0.038359389]
,[0.035600016 0.038359389 0]]
[[0 0.014285714 0.035600016]
,[0.014285714 0 0.038359389]
,[0.035600016 0.038359389 0]]
so adding these two then results has 3 by 3 matrix
how could I efficiently add these two lists?
Can i solve using numpy:
>>> a = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
>>> b = [[4, 5, 6], [4, 5, 6], [4, 5, 6]]
>>> from numpy import array, sum
>>> list(array(a) + array(b))
[array([5, 7, 9]), array([5, 7, 9]), array([5, 7, 9])]
OR
>>> sum([a, b], axis=0)
array([[5, 7, 9],
[5, 7, 9],
[5, 7, 9]])
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With