1.给出你10个点(xi,yi),先找出xi+yi最大的那一组temp,然后在从剩下的九组中找到离temp最近的点temp1,紧接着再从剩下的8个点钟找到离temp1最近的点temp2*。
import numpy as np
s='31.816767,119.98048|30.90029,120.09334|30.057623,120.59004|32.048153,118.79044|31.236351,121.48024|30.752031,120.76203|31.581388,120.30619|30.279995,120.16161|31.657412,119.0347|31.305141,120.59173'
line=s.split('|')
aa=[]
b=[]
#先找出最大的点temp
for i in range(len(line)):
line[i]=line[i].split(',')
aa.append(list(map(float,line[i])))
b.append(sum(list(map(float,line[i]))))
index=b.index(max(b))
temp=aa[index]
# 存储整理后的结果
aa1=[]
aa1.append(temp)
aa.remove(temp)
ll=len(aa)
#来回调用bijiao函数,找出temp1,temp2....
for i in range(ll):
ss= bijiao(aa,temp)
index=ss.index(min(ss))
temp=aa[index]
aa1.append(temp)
aa.remove(temp)
print(aa1)
# 从数组中找出离给定点最近的点
def bijiao(aa,temp):
ss=[]
for i in range(len(aa)):
s=(aa[i][0]-temp[0])*(aa[i][0]-temp[0])+(aa[i][1]-temp[1])*(aa[i][1]-temp[1])
ss.append(np.sqrt(s))
return ss
2.找出浏览过商品但是没买的用户ID,商品ID,商品名称