Element-wise addition of 2 lists?

后端 未结 16 1439
感动是毒
感动是毒 2020-11-22 07:48

I have now:

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

I wish to have:

[1, 2, 3]
 +  +  +         


        
16条回答
  •  执笔经年
    2020-11-22 08:33

    I haven't timed it but I suspect this would be pretty quick:

    import numpy as np
    list1=[1, 2, 3]
    list2=[4, 5, 6]
    
    list_sum = (np.add(list1, list2)).tolist()
    
    [5, 7, 9]
    

提交回复
热议问题