快捷导航

python3 二维数组的切片

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

result = dims[c//2::1, c//2::1]
python3 中 //是整除
例如 2/1 #2.0, 2//1 #2
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP