Python 主要错误是;名称';自我';“未定义”;
您不需要输入数据,这里的示例非常繁重,代码在没有“.self”和“init”的情况下工作,但我确实需要在下面这样的单独函数中对其进行良好的格式化。提前谢谢你Python 主要错误是;名称';自我';“未定义”;,python,Python,您不需要输入数据,这里的示例非常繁重,代码在没有“.self”和“init”的情况下工作,但我确实需要在下面这样的单独函数中对其进行良好的格式化。提前谢谢你 class PlateString: def __init__(self, threshold=0.05): self.threshold = threshold max_list_from_all_plates = [] for single_lp in seq:
class PlateString:
def __init__(self, threshold=0.05):
self.threshold = threshold
max_list_from_all_plates = []
for single_lp in seq:
maximum_plate_prob = []
possible_plate_prob = []
max_list = []
plateresults = []
for sign in single_lp:
high_indexes = []
for prob_id in range(0,len(sign)):
if self.threshold<sign[prob_id]:
high_indexes.append([sign[prob_id], prob_id, CATEGORIES[prob_id]])
max_list.append(high_indexes)
max_list_from_all_plates.append(max_list)
listaMain = []
ListaVal = []
self.checklen(max_list_from_all_plates, listaMain, ListaVal, plateresults)
def checklen(self, max_list_from_all_plates, listaMain, ListaVal, plateresults):
for plate in max_list_from_all_plates:
maxlen = 0
if len(plate) > maxlen:
maxlen = len(plate)
print(maxlen)
textPlate : str= ""
sumplate = 0
for probabilities in plate:
znakMax : str = ""
probabilityMax : float = 0
for probability in probabilities:
if(probabilityMax<probability[0]):
probabilityMax = probability[0]
znakMax = probability[2]
valMax = probability[0]
textPlate += znakMax
sumplate += valMax
listaMain.append(textPlate)
ListaVal.append(sumplate)
for i in range(len(listaMain)):
info = [ListaVal[i], listaMain[i]]
plateresults.append(info)
print(plateresults)
if __name__ == '__main__':
PlateString(threshold=0.05).checklen(self, max_list_from_all_plates, listaMain, ListaVal, plateresults)
类模板字符串:
定义初始值(自,阈值=0.05):
self.threshold=阈值
来自所有板材的最大列表=[]
对于以下各项中的单个lp:
最大板直径=[]
可能的\u板\u问题=[]
最大值列表=[]
plateresults=[]
对于登录单_lp:
高_指数=[]
对于范围(0,长度(符号))内的问题id:
如果self.threshold maxlen:
最大长度=长度(板)
打印(maxlen)
textPlate:str=“”
集水坑板=0
对于板中的概率:
znakMax:str=“”
概率max:float=0
对于概率中的概率:
如果(概率maxl=0
计数=0
for i in listyofechletter:
r = 0
r += r
s = i[r]
#print(i)
if i[r] == i[r+1]:
#print("the same",i)
counts += 1
res = sum(1 for x in listyofechletter if i[r] == i[r+1])
#print(res, i)
#if True:
#counts =+ 1
else:
#print("not the same", i)
res2 = sum(1 for y in listyofechletter if i[r] == i[r+1])
print(res2, i)
print(counts, i)
问题是我使用了=+而不是+=你“想用字母来比较它”是什么意思?你想按最后一个元素对列表排序吗?如果是这样,那么使用sorted
和key
参数。作为key
你可以添加lambda x:x[2]
,这意味着你可以按第三个元素排序(在你的情况下是一个字母)。我不想用简单的逻辑运算符(如if a==b)来使用我自己想要的排序函数。你能提供listyofechletter
让我们了解如何达到你的期望吗?