numpy - python element wise add in list of list with other list -
i checked similar problem @ sum of n lists element-wise python
but mine little bit more complicate cause adding list of list list of list
my list looks 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 2 results has 3 3 matrix
how efficiently add these 2 lists?
can solve using numpy:
>>> = [[1, 2, 3], [1, 2, 3], [1, 2, 3]] >>> b = [[4, 5, 6], [4, 5, 6], [4, 5, 6]] >>> 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]]) >>>
Comments
Post a Comment