- 1

Pandas pandas pandas

Has anyone done the 'pandas pandas pandas' question at the end of the data science course. I passed all the cases except case 3 which is locked.

23rd Jun 2021, 3:06 AM
tom hands
tom hands - avatar
3 Respostas
+ 1
import numpy as np import math n = int(input()) points = [] while n > 0: points.append( [float(i) for i in input().split()]) n -= 1 cluster1 = [] cluster2 = [] c1 = [0,0] c2 = [2,2] for point in points: x3 = np.array(c2) x1 = np.array(c1) x2 = np.array(point) dist1 =np.sqrt(((x1-x2)**2).sum()) dist2 = np.sqrt(((x3-x2)**2).sum()) if dist1 <= dist2 : cluster1.append(point) else: cluster2.append(point) if cluster1 == []: print(None ) if cluster2 == []: print(None ) result = np.array(cluster1) result2 = np.array(cluster2) avg = np.average(result , axis=0) avg2 = np.average(result2 , axis=0) #print(cluster1[0]) avg = np.round(avg, decimals =2) avg2 = np.round(avg2, decimals =2) print (avg) print (avg2)
23rd Jun 2021, 7:13 AM
tom hands
tom hands - avatar