python報錯:TypeError: slice indices must be integers or None or have an __index__ method


在使用Python進行矩陣操作時,當內部含有除法時,會產生錯誤:

TypeError: slice indices must be integers or None or have an __index__ method

例如:

 

img=np.hstack((a[:,0:100/2],b[:,100/2,:])) 

由於除法/自動產生的類型是浮點型,因此出現上述錯誤,修正方法為,將/更改為//

代碼為:

 

img=np.hstack((a[:,0:100//2],b[:,100//2,:])) 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM