TypeError: slice indices must be integers or None or have an __index__ method【解决办法】

今天爱分享给大家带来TypeError: slice indices must be integers or None or have an __index__ method【解决办法】,希望能够帮助到大家。

Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法
在执行Python 3脚本时,报错:TypeError: slice indices must be integers or None or have an __index__ method,报错位置:

    # Now add left and right halves of images in each level
    ls_image = []
    for la, lb in zip(lp_image1, lp_image2):
        rows, cols, dpt = la.shape
        ls = np.hstack((la[:, 0:cols / 2], lb[:, cols / 2:]))
        ls_image.append(ls)

出错代码行为:

ls = np.hstack((la[:, 0:cols / 2], lb[:, cols / 2:]))

问题原因:

In Python 3.x, 5 / 2 will return 2.5 and 5 // 2 will return 2. The former is floating point division, and the latter is floor division, sometimes also called integer division.

In Python 2.2 or later in the 2.x line, there is no difference for integers unless you perform a from __future__ import division, which causes Python 2.x to adopt the 3.x behavior.

Regardless of the future import, 5.0 // 2 will return 2.0 since that’s the floor division result of the operation.

解决方案:

将出错代码行改为:

ls = np.hstack((la[:, 0:cols // 2], lb[:, cols // 2:]))
原文链接:https://blog.itblood.com/1579.html,转载请注明出处。
0
如此剧烈的疼痛v0.11.7R 精翻版[PC+安卓/8.07G/更新]Such a Sharp Pain v0.11.7R [欧美SLG/精翻/炼铜]
如此剧烈的疼痛v0.11.7R 精翻版[PC+安卓/8.07G/更新]Such a Sharp Pain v0.11.7R [欧美SLG/精翻/炼铜]
刚刚 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?