from math import sqrt """ Clustering """ def square(a): return a*a class Point: def __init__(self, coordinates): self.coordinates = coordinates self.squares = [square(coordinate) for coordinate in self.coordinates] def distance(self, other): self.pairs = zip(self.squares, other.squares) return sqrt(abs(sum([(a-b) for a,b in self.pairs]))) class Cluster: def __init__(self, points): self.points = points self.matrix = self.blank_matrix(5) def blank_matrix(n): return [ [None] * i for i in range(n)] #matrix = [(10, 5), (20, 20), (30, 10), (30, 15), (5, 10)] #matrix = [Point(x) for x in matrix] cluster = Cluster([(10, 5), (20, 20), (30, 10), (30, 15), (5, 10)]) print cluster.points #a = matrix[1] #b = matrix[2] #print a.distance(b)