ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

【python】Python ERROR: IndexError

【python】Python ERROR: IndexError

IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

碰到的问题如上所示,这个问题其实是index的一个问题,而且主要是python2和python3会存在是否取整的问题,使用python3就特别容易出现index的问题,方法也很简单,强制转成int型就可以了

#test_acc[(it // test_interval)] = correct / 1e4test_acc[int((it//test_interval))]=correct/1e4

问题解决!

返回列表