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