a = [1,2,3]
b = [4,5,6]
a+b
Out[11]: [1, 2, 3, 4, 5, 6]
a/b
Traceback (most recent call last):
File "
a/b
TypeError: unsupported operand type(s) for /: 'list' and 'list'
问题在于:两个list不能直接算数运算
解决方案:转成np运算 ↓
aa = np.array(a)
bb = np.array(b)
aa,bb
Out[15]: (array([1, 2, 3]), array([4, 5, 6]))
然后运算看看:
aa+bb
Out[16]: array([5, 7, 9])
aa/bb
Out[17]: array([0.25, 0.4 , 0.5 ])