Error Box 之 'zip' object is not subscriptable

TypeError: 'zip' object is not subscriptable

def create_ssd_anchors(num_layers=6,
                       min_scale=0.2,
                       max_scale=0.95):
  box_specs_list = []
  scales = [min_scale + (max_scale - min_scale) * i / (num_layers - 1)
            for i in range(num_layers)] + [1.0]
  return zip(scales[:-1], scales[1:])

self.anchors = create_ssd_anchors()
min_size, max_size = self.anchors[0]

这是因为在Python 3.x中,zip返回一个生成器对象。这个对象不是一个列表。

解决方法:

def create_ssd_anchors(num_layers=6,
                       min_scale=0.2,
                       max_scale=0.95):
  box_specs_list = []
  scales = [min_scale + (max_scale - min_scale) * i / (num_layers - 1)
            for i in range(num_layers)] + [1.0]
  return list(zip(scales[:-1], scales[1:]))

self.anchors = create_ssd_anchors()
min_size, max_size = self.anchors[0]

TypeError: object of type 'zip' has no len()

同理!

阅读更多

TypeError: 'NoneType' object is not subscriptable

10-09

python3写的程序不知道这个错误怎么改,报错的内容在图片里面。![图片说明](https://img-ask.csdn.net/upload/201710/09/1507511766_694476.png)nn```n # -*- coding: utf-8 -*-n"""nCreated on Sun Oct 8 20:20:44 2017nn@author: lln"""nnimport numpy as npnndef findMax1(array):n if len(array)<1:#len(array)得到列表长度n return [-1,-1]n index = 1n unit = array[index]n for j in range(1,len(array)):n if array[j] > array[index+1] and array[j] > array[index-1]:#if的含多条件语句的写法n unit = array[j]n return [unit,j]#返回的是一个列表类型,最大值和它的坐标1nndef getMax1(matrix, column_Num):n array = [col[column_Num] for col in matrix]#将找到的列循环遍历后放到列表中n return findMax1(array)n ndef getPeak(matrix, leftCol, rightCol):n if rightCol <= leftCol:n r = getMax1(matrix,leftCol)n r.append(leftCol)n mid = int((leftCol + rightCol) / 2)n unit = getMax1(matrix, mid)#返回的变量名要和接收传参的名字一样nn rightElem = getMax1(matrix, mid+1)n if leftCol == rightCol - 1:n leftElem = unitn if leftElem[0] > rightElem[0]:n r = leftElemn r.append(mid)n else:n r = rightElemn r.append(mid+1)n return rnn leftElem = getMax1(matrix, mid-1)n if unit[0] >= leftElem[0] and unit[0] >= rightElem[0]:n unit.append(mid)n return unitn if unit[0] < leftElem[0]:n return getPeak(matrix,leftCol,mid-1)n return getPeak(matrix,mid+1,rightCol)nnnnprint("please input row:")nn = int(input())nprint("please input column:")nm = int(input())nmatrix = np.random.randint(100,999,size=[n,m])nprint(matrix)nnresult = getPeak(matrix,0,len(matrix[0])-1)nnprint(result)nnn```nn

TypeError: 'NoneType' object is not subscriptable python3写的代码

10-09

报错在图片里面,不清楚具体怎么改。[img=http://img.bbs.csdn.net/upload/201710/09/1507512052_96666.png][/img]rn[code=python]rn# -*- coding: utf-8 -*-rn"""rnCreated on Sun Oct 8 20:20:44 2017rnrn@author: llrn"""rnrnimport numpy as nprnrndef findMax1(array):rn if len(array)<1:#len(array)得到列表长度rn return [-1,-1]rn index = 1rn unit = array[index]rn for j in range(1,len(array)):rn if array[j] > array[index+1] and array[j] > array[index-1]:#if的含多条件语句的写法rn unit = array[j]rn return [unit,j]#返回的是一个列表类型,最大值和它的坐标1rnrndef getMax1(matrix, column_Num):rn array = [col[column_Num] for col in matrix]#将找到的列循环遍历后放到列表中rn return findMax1(array)rn rndef getPeak(matrix, leftCol, rightCol):rn if rightCol <= leftCol:rn r = getMax1(matrix,leftCol)rn r.append(leftCol)rn mid = int((leftCol + rightCol) / 2)rn unit = getMax1(matrix, mid)#返回的变量名要和接收传参的名字一样rnrn rightElem = getMax1(matrix, mid+1)rn if leftCol == rightCol - 1:rn leftElem = unitrn if leftElem[0] > rightElem[0]:rn r = leftElemrn r.append(mid)rn else:rn r = rightElemrn r.append(mid+1)rn return rrnrn leftElem = getMax1(matrix, mid-1)rn if unit[0] >= leftElem[0] and unit[0] >= rightElem[0]:rn unit.append(mid)rn return unitrn if unit[0] < leftElem[0]:rn return getPeak(matrix,leftCol,mid-1)rn return getPeak(matrix,mid+1,rightCol)rnrnrnrnprint("please input row:")rnn = int(input())rnprint("please input column:")rnm = int(input())rnmatrix = np.random.randint(100,999,size=[n,m])rnprint(matrix)rnrnresult = getPeak(matrix,0,len(matrix[0])-1)rnrnprint(result)rnrn[/code]

没有更多推荐了,返回首页