需求:
a=[0,0,1]
b=[4,5,6]
现将list a与 list b按位相加,其结果为[4,5,7]
方法一:
c=[a[i]+b[i] for i in range(min(len(a),len(b)))]
方法二:
c=list(map(lambda x :x[0]+x[1] ,zip(a,b)))
方法三:
调用numpy库
import numpy as np
c = np.array(a) + np.array(b)
需求:
a=[0,0,1]
b=[4,5,6]
现将list a与 list b按位相加,其结果为[4,5,7]
c=[a[i]+b[i] for i in range(min(len(a),len(b)))]
c=list(map(lambda x :x[0]+x[1] ,zip(a,b)))
调用numpy库
import numpy as np
c = np.array(a) + np.array(b)