19.Python performs deduplication operations on list elements

Problem description: There is a piece of tracking information, the purpose is to find the category information with the greatest confidence, and perform category jump and area change statistics;

track_data=[[0.9,3,'i'],[0.7,3,'i'],[0.1,3,'i'],[0.9,2,'o'],[0.98,2,'o '],[0.7,3,'i'],[0.1,3,'i'],[0.9,2,'o']] means score, category information area location

Score: the confidence level of category information

Category information: Target A=3 Target B=2 

Area information i is the inner area o is the outer area

Result: [[0.9, 3,'i'], [0.9, 2,'o'], [0.7, 3,'i'], [0.9, 2,'o']]

import os

track_data=[[951, 2, 1100, 247, 1229, 336, 1, 0, 0, True, False, 0.5361185669898987, 3, 0, 'o'], [952, 2, 1055, 250, 1184, 339, 0.45901639344262296, 1, 1, True, False, 0.5182264447212219, 3, 1, 'o'], [953, 2, 1044, 148, 1202, 313, 0.27620309951060357, 0, 0, True, False, 0.7706855535507202, 3, 0, 'o'], [954, 2, 1020, 99, 1181, 277, 0.4769396842531372, 0, 0, True, False, 0.5893790125846863, 3, 0, 'o'], [955, 2, 1000, 65, 1161, 243, 0.5485788392953637, 1, 1, True, False, 0.5893790125846863, 3, 1, 'i'], [956, 2, 979, 25, 1142, 268, 0.5879370100718755, 0, 0, True, False, 0.7298511266708374, 3, 0, 'i'], [957, 2, 984, 23, 1143, 259, 0.9205946067080003, 0, 0, True, False, 0.7313498854637146, 3, 0, 'i'], [958, 2, 985, 20, 1144, 256, 0.9628602814249098, 1, 1, True, False, 0.7313498854637146, 3, 1, 'i'], [959, 2, 978, 53, 1151, 262, 0.779562361124529, 0, 0, True, False, 0.7412099838256836, 3, 0, 'i'], [960, 2, 976, 89, 1158, 263, 0.789766729997889, 0, 0, True, False, 0.6838870048522949, 3, 0, 'o'], [961, 2, 980, 100, 1162, 274, 0.8453470077501312, 1, 1, True, False, 0.6838870048522949, 3, 1, 'o'], [962, 2, 985, 105, 1167, 279, 0.8949824970828472, 2, 2, True, False, 0.6838870048522949, 3, 1, 'o'], [963, 2, 985, 105, 1167, 279, 1.0, 3, 3, True, False, 0.6838870048522949, 3, 1, 'o'], [964, 2, 980, 105, 1162, 279, 0.946524064171123, 4, 4, True, False, 0.6838870048522949, 3, 1, 'o'], [965, 2, 980, 105, 1162, 279, 1.0, 5, 5, True, False, 0.6838870048522949, 3, 1, 'o'], [966, 2, 975, 105, 1157, 279, 0.946524064171123, 6, 6, True, True, 0.6838870048522949, 3, 1, 'o']]


k=len(track_data)
m=0
for i in range(0,k):
    for j in range(i+1,k):    
      j=j-m
      if j>=k:
         break

      if track_data[i][-1]!=track_data[j][-1]:
         m=0
         break
      elif track_data[i][-4]>=track_data[j][-4]:
           track_data.pop(j)
           k=k-1
           m=m+1 
           
      else:
           track_data[i]=track_data[j].copy()
           track_data.pop(j)
           k=k-1
           m=m+1 


print (track_data)

 

 

[[953, 2, 1044, 148, 1202, 313, 0.27620309951060357, 0, 0, True, False, 0.7706855535507202, 3, 0, 'o'], [959, 2, 978, 53, 1151, 262, 0.779562361124529, 0, 0, True, False, 0.7412099838256836, 3, 0, 'i'], [960, 2, 976, 89, 1158, 263, 0.789766729997889, 0, 0, True, False, 0.6838870048522949, 3, 0, 'o']]
data=[]
for track_id,track_item in enumerate(track_data):
    if track_id==0:
       data.append(track_item)
       continue
    if data[-1][-1]!=track_item[-1] or data[-1][-3]!=track_item[-3]:
       data.append(track_item)
    if data[-1][-4]>track_item[-4] and data[-1][-1]==track_item[-1]:
       continue
    elif data[-1][-4]<track_item[-4] and data[-1][-1]==track_item[-1]:
       data[-1]=track_item

print (data,"data-----------")

 

Guess you like

Origin blog.csdn.net/sxj731533730/article/details/103819627