当前位置:主页 > 软件编程 > Python代码 >

python中利用numpy.array()实现俩个数值列表的对应相加方法

时间:2021-03-27 09:31:07 | 栏目:Python代码 | 点击:

小编想把用python将列表[1,1,1,1,1,1,1,1,1,1] 和 列表 [2,2,2,2,2,2,2,2,2,2]对应相加成[3,3,3,3,3,3,3,3,3,3]。

代码如下:

import numpy 
 
a = numpy.array([1,1,1,1,1,1,1,1,1,1])
 
b = numpy.array([2,2,2,2,2,2,2,2,2,2])
 
c = a + b
 
print(type(c))
 
print(list(c))

输出结果为:

<class 'numpy.ndarray'>

[3,3,3,3,3,3,3,3,3,3]

您可能感兴趣的文章:

相关文章