Войти
или
Зарегистрироваться
Маркетплейс
Курсы
Учебник
Учебник 2.0
ОГЭ/ЕГЭ
Олимпиады
Рубрикатор
Компилятор
Онлайн Компилятор
Компилятор Python (lite)
Редактор HTML Code
Статья Автор:
Поджарский Давид
y reshau 27 GOIDA
def dist(xy,pos): r = (xy[0] - pos[0]) ** 2 + (xy[1] - pos[1]) ** 2 return r ** 0.5, pos fname = '27.11.B_20206.txt' dots = [(0,0,0)] Clasters ={0 : [], 1 : [], 2 : []} ksize = 1000 for s in open(fname): s= s.replace(',', '.') x, y = map(float, s.split()) r, pos = min(dist((x, y), dot) for dot in dots) Clasters[pos[2]].append((x, y)) Centrs = [] for ind in Clasters: if len(Clasters[ind]) == 0 : continue centr = None for xy in Clasters[ind]: r =sum(dist(dot,xy)[0] for dot in Clasters[ind]) if centr == None or centr[0] > r : centr = (r,xy) Centrs.append(centr[1]) print(ind, len(Clasters[ind]),centr) px = sum(xy[0] for xy in Centrs)/len(Centrs) py = sum(xy[1] for xy in Centrs)/len(Centrs) print(px*ksize,py*ksize) import matplotlib.pyplot as plt colors =['red', 'green', 'blue', 'broun', 'black'] for ind in Clasters: plt.scatter([xy[0] for xy in Clasters[ind]], [xy[1] for xy in Clasters[ind]], color = colors[ind % 5]) plt.show()
×
Прикрепленные файлы
27.11.A_20206.txt
27.11.B_20206.txt
Чтобы оставить комментарий нужна авторизация
Печать