algorithms/k-means/algorithms.py
def _average(data, data_type):
        """
        Return the coordinates of the barycenter if data are points, the average word if data are words.
        :type data_type: str
        :param data_type: Indicates if the data are points or words.
        :return: Average data
        """

        if data_type == 'points':
            """
                Return the coordinates of the barycenter of the tuples in the list distances
            """
            n = len(data)
            d = len(data[0])  # Number of coordinates
            B = [0 for k in range(d)]

            for point in data:
                for i in range(d):
                    B[i] += point[i]

            #FIXME: add comments or change method.
            B = map(lambda x: x / n, B)
            return tuple(B)

        elif data_type == 'words':
            """
                Return the average word from the list of words.
            """

            max_length = max(map(len, data))
            average_word = ['' for k in range(max_length)]

            # Make all the words the same length
            # FIXME: add comments
            for i in range(len(data)):
                n = len(data[i])
                data[i] = data[i] + (max_length - n) * ' '

            for k in range(max_length):
                listchar = [w[k] for w in data]  # List of k-th characters in each word.
                average_word[k] = Counter(listchar).most_common(1)[0][0]

            return ''.join(average_word)  # Convert to string

        else:
            raise Exception("Data type not implemented")

        Return the coordinates of the barycenter if data are points, the average word if data are words.
        :type data_type: str
        :param data_type: Indicates if the data are points or words.
        :return: Average data
        
Return the coordinates of the barycenter if data are points, the average word if data are words.
Return the coordinates of the barycenter if data are points the average word if data are words .
def _average(data, data_type):
        if data_type == 'points':
            n = len(data)
            d = len(data[0])  
            B = [0 for k in range(d)]
            for point in data:
                for i in range(d):
                    B[i] += point[i]
            B = map(lambda x: x / n, B)
            return tuple(B)
        elif data_type == 'words':
            max_length = max(map(len, data))
            average_word = ['' for k in range(max_length)]
            for i in range(len(data)):
                n = len(data[i])
                data[i] = data[i] + (max_length - n) * ' '
            for k in range(max_length):
                listchar = [w[k] for w in data]  
                average_word[k] = Counter(listchar).most_common(1)[0][0]
            return ''.join(average_word)  
        else:
            raise Exception("Data type not implemented")
def _average ( data , data_type ) : if data_type == 'points' : """
                Return the coordinates of the barycenter of the tuples in the list distances
            """ n = len ( data ) d = len ( data [ 0 ] ) B = [ 0 for k in range ( d ) ] for point in data : for i in range ( d ) : B [ i ] += point [ i ] B = map ( lambda x : x / n , B ) return tuple ( B ) elif data_type == 'words' : """
                Return the average word from the list of words.
            """ max_length = max ( map ( len , data ) ) average_word = [ '' for k in range ( max_length ) ] for i in range ( len ( data ) ) : n = len ( data [ i ] ) data [ i ] = data [ i ] + ( max_length - n ) * ' ' for k in range ( max_length ) : listchar = [ w [ k ] for w in data ] average_word [ k ] = Counter ( listchar ) . most_common ( 1 ) [ 0 ] [ 0 ] return '' . join ( average_word ) else : raise Exception ( "Data type not implemented" )
Return the coordinates of the barycenter if data are points, the average word if data are words.
Return the coordinates of the barycenter if data are points the average word if data are words .
"""
        Return the coordinates of the barycenter if data are points, the average word if data are words.
        :type data_type: str
        :param data_type: Indicates if the data are points or words.
        :return: Average data
        """ """
                Return the coordinates of the barycenter of the tuples in the list distances
            """ # Number of coordinates #FIXME: add comments or change method. """
                Return the average word from the list of words.
            """ # Make all the words the same length # FIXME: add comments # List of k-th characters in each word. # Convert to string
None
data
data_type
Indicates if the data are points or words.
Indicates if the data are points or words .