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