Home Python cluster module confusing class methods
 I was trying to write a module for clustering, but class method are a little confusing for me import numpy as np class SingleLinkage: def __init__(self, x, k): self.data = x n=x.shape[0] self.clusters={i : [i] for i in range(n)} self.k=k self.y=None def euc(self,x,y): self.x=x if self.y==None: self.y=y return np.sqrt(np.sum((x-y)**2)) def clustDist(self, i, j): cd=np.Inf for idx in self.clusters[i]: for idy in self.clusters[j]: cd=min(cd,self.euc(self.data[idx], self.data[idy])) return cd def findClothest(self): cd=np.Inf for i in self.clusters: for j in self.clusters: if i!=j and clustDist(i,j)>> x = np.array ([[0 , 0] , [0 , 0.1] , [1 , 1]]) >>> hc = lc.SingleLinkage (x , 2) >>> hc.clusters {0: [0], 1: [1], 2: [2]}  But should be different: >>> hc.clusters {0: [0 , 1] , 1: [2]}  I know that probably the error is in the init function. How should I change it?