Pav*_*zev 5 python numpy list unique
I have a list of coordinates like
list_cor =
[[4190091.4195999987, 7410226.618699998],
[4190033.2124999985, 7410220.0823],
[4190033.2124999985, 7410220.0823],
[4190035.7005000003, 7410208.670500003],
[4190033.2124999985, 7410220.0823],
[4190022.768599998, 7410217.844300002]]
Run Code Online (Sandbox Code Playgroud)
I need to get only these values:
[[4190091.4195999987, 7410226.618699998],
[4190035.7005000003, 7410208.670500003],
[4190022.768599998, 7410217.844300002]]
Run Code Online (Sandbox Code Playgroud)
Tried numpy.unique() but it adds this item [4190033.2124999985, 7410220.0823], which I don't need.
小智 7
使用numpy.unique与axis和return_counts参数:
arr, uniq_cnt = np.unique(list_cor, axis=0, return_counts=True)
uniq_arr = arr[uniq_cnt==1]
Run Code Online (Sandbox Code Playgroud)
你快到了 :
coords=[ x+1j*y for (x,y) in list_cor] # using complex; a way for grouping
uniques,counts=np.unique(coords,return_counts=True)
res=[ [x.real,x.imag] for x in uniques[counts==1] ] # ungroup
Run Code Online (Sandbox Code Playgroud)
为了 :
[[4190022.7685999982, 7410217.8443000019],
[4190035.7005000003, 7410208.6705000028],
[4190091.4195999987, 7410226.6186999977]]
Run Code Online (Sandbox Code Playgroud)