需求:

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)

相关文章:

  • 2022-03-08
  • 2022-12-23
  • 2022-01-27
  • 2022-12-23
  • 2022-01-03
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2019-09-04
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
相关资源
相似解决方案