dims = np.array([[1, 2, 3, 4],[5, 6, 7, 8]])
c = 2
result = dims[c/2::1, c/2::1]
这个在python2.7.10上运行无问题,但在python3.6.2上报错
TypeError: slice indices must be integers or None or have an __index__ method
dims = np.array([[1, 2, 3, 4],[5, 6, 7, 8]])
c = 2
result = dims[c/2::1, c/2::1]
这个在python2.7.10上运行无问题,但在python3.6.2上报错
TypeError: slice indices must be integers or None or have an __index__ method
1 回答2.4k 阅读✓ 已解决
1 回答966 阅读
result = dims[c//2::1, c//2::1]
python3 中 //是整除
例如 2/1 #2.0, 2//1 #2