zoukankan      html  css  js  c++  java
  • 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,:])) 
  • 相关阅读:
    如何为创建大量实例节省内存?
    4-5
    4-6
    4-4
    4-3
    4-2
    3-11
    4-1
    3-10
    3-8
  • 原文地址:https://www.cnblogs.com/klausage/p/10272404.html
Copyright © 2011-2022 走看看