a=[1,2,3]
b=np.array([4,5,6])
运行:
c=1-a
报错:
TypeError: unsupported operand type(s) for -: ‘int’ and ‘list’
TypeError: unsupported operand type(s) for -: ‘int‘ and ‘list‘ 解决过程

运行:
c=1-b
结果:
TypeError: unsupported operand type(s) for -: ‘int‘ and ‘list‘ 解决过程

错误表示:不支持 int整型和 list列表的 减法运算,列表不是numpy的数组,没有广播运算。
因此需要将列表列表变成numpy数组,进行广播运算,就不会报错了。
TypeError: unsupported operand type(s) for -: ‘int‘ and ‘list‘ 解决过程
同理对于加法也一样:
TypeError: unsupported operand type(s) for +: ‘int’ and ‘list’

相关文章:

  • 2022-12-23
  • 2022-02-10
  • 2021-08-04
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2021-12-26
  • 2021-09-10
  • 2021-09-01
相关资源
相似解决方案