algorithms/k-means/algorithms.py
def choose_init_centers(this):
        """
        Choose k centers among data randomly.
        """

        if this.centers is not None:
            if len(this.centers) != this.k:
                raise Exception("Number of centers provided incorrect.")
        else:
            this.centers = []
            pTmp = list(this.data)
            for i in range(this.k):
                this.centers.append(pTmp.pop(randint(0, len(pTmp) - 1)))

        Choose k centers among data randomly.
        
Choose k centers among data randomly.
Choose k centers among data randomly .
def choose_init_centers(this):
        if this.centers is not None:
            if len(this.centers) != this.k:
                raise Exception("Number of centers provided incorrect.")
        else:
            this.centers = []
            pTmp = list(this.data)
            for i in range(this.k):
                this.centers.append(pTmp.pop(randint(0, len(pTmp) - 1)))
def choose_init_centers ( this ) : if this . centers is not None : if len ( this . centers ) != this . k : raise Exception ( "Number of centers provided incorrect." ) else : this . centers = [ ] pTmp = list ( this . data ) for i in range ( this . k ) : this . centers . append ( pTmp . pop ( randint ( 0 , len ( pTmp ) - 1 ) ) )
Choose k centers among data randomly.
Choose k centers among data randomly .
"""
        Choose k centers among data randomly.
        """
this