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

声明:本文为博主原创文章,不可转载 https://blog.csdn.net/jjddss/article/details/73469104

在使用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,:])) 

猜你喜欢

转载自blog.csdn.net/qq_33485434/article/details/82685468