TypeError: unsupported operand type(s) for -: ‘int‘ and ‘list‘ 解决过程
a=[1,2,3]
b=np.array([4,5,6])
运行:
c=1-a
报错:
TypeError: unsupported operand type(s) for -: ‘int’ and ‘list’
运行:
c=1-b
结果:
错误表示:不支持 int整型和 list列表的 减法运算,列表不是numpy的数组,没有广播运算。
因此需要将列表列表变成numpy数组,进行广播运算,就不会报错了。
同理对于加法也一样:
TypeError: unsupported operand type(s) for +: ‘int’ and ‘list’