- 1

Assume that there are two clusters among the given two-dimensional data points and two random points (0, 0), and (2, 2) are the

import numpy as np n = int(input()) # Initial centroids p1 = np.array([0, 0]) # 1st point p2 = np.array([2, 2]) # 2nd point class_1 = [] class_2 = [] XY = [] for i in range(n): XY.append([float(i) for i in input().split()]) new_point = np.array(XY[-1]) dist1 = np.sqrt(((new_point - p1) ** 2).sum()) dist2 = np.sqrt(((new_point - p2) ** 2).sum()) if dist1 < dist2: class_1.append(XY[-1]) elif dist1 > dist2: class_2.append(XY[-1]) else: class_1.append(XY[-1]) if len(class_1)>0: print(np.average(np.array(class_1),axis=0).round(2)) else: print(None) if len(class_2)>0: print(np.average(np.array(class_2),axis=0).round(2)) else: print(None)

18th Apr 2022, 1:15 PM
Shubham Mandgaonkar
1 Resposta