我似乎找不到我已经摆脱范围问题的问题:
layerZ = [layer_1,layer_2,layer_3,layer_4,layer_5,layer_6,layer_7,layer_8,layer_9,layer_10,layer_11,layer_12,layer_13]
for x in range(0, 12):
layerZ_total = [np.size(layerZ[x])]
layerZ_sp = [np.count_nonzero(layerZ[x]==0)]
layerZ_nonSp = [np.count_nonzero(layerZ[x])]
#Printing the results on scree to trace
print "Layer:",x+1,"Threshhold:",repr(ths),"Total Parameters: ",layerZ_totParam[x],"# Sp: ",layerZ_sp[x],"# Remained : ",layerZ_nonSp[x],"Sp %: ",float(layerZ_sp[x])/layerZ_total[x]
这应该有所帮助:
layerZ = [layer_1,layer_2,layer_3,layer_4,layer_5,layer_6,layer_7,layer_8,layer_9,layer_10,layer_11,layer_12,layer_13]
layerZ_total = []
layerZ_sp = []
layerZ_nonSp = []
for x in range(0, 12):
layerZ_total.append(np.size(layerZ[x]))
layerZ_sp.append(np.count_nonzero(layerZ[x]==0))
layerZ_nonSp.append(np.count_nonzero(layerZ[x]))
#Printing the results on scree to trace
print "Layer:",x+1,"Threshhold:",repr(ths),"Total Parameters: ",layerZ_total[x],"# Sp: ",layerZ_sp[x],"# Remained : ",layerZ_nonSp[x],"Sp %: ",float(layerZ_sp[x])/layerZ_total[x]
在您的代码中,列表 layerZ_total
, layerZ_sp
和 layerZ_nonSp
在循环内每次都被重新定位,因此在循环中每次都有一个值,因此,当您尝试访问某些x index
时,在它们内部仅包含一个index 0
处的一个元素,list index out of range
错误弹出。p>,如果您要在layerZ
列表的每个layer_*
上进行处理(取决于您的要求),则需要使用range(0, 13)
,就像这样做之后,x
将对0
进行CC_11,从而处理layerZ
中的每个layer
列表