TypeError


1、only size-1 arrays can be converted to Python scalars

问题来源:需要把一个float数组A转为int,于是直接在代码中写了 B=int(A),从而报错。

原因:int函数只能对单个数字进行,而不能对一个数组进行

解决方法:用map函数,对数组中的每个元素整数化

B=list( map( int , A ) )

 

2、list indices must be integers or slices, not tuple

(7条消息) TypeError: list indices must be integers or slices, not tuple_yp736628082的博客-CSDN博客


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM