algorithms/k-means/utilities.py
def read_data(filename, skip_first_line=False, ignore_first_column=False, data_type='points'):
    """
    Loads data from a csv file and returns the corresponding list. See provided input files for format convention.

    :param filename: csv file name.

    :param skip_first_line: if True, the first line is not read. Default value: False.

    :param ignore_first_column: if True, the first column is ignored. Default value: False.

    :param data_type: either 'points' or 'words'.

    :return: a list of data.
    """

    f = open(filename, 'r')
    if skip_first_line:
        f.readline()

    data = []

    if data_type == 'points':
        for line in f:
            line = line.split(",")
            line[1:] = [float(x) for x in line[1:]]
            if ignore_first_column:
                line = line[1:]
            data.append(tuple(line))
    else:
        for line in f:
            line = line.split(' ')
            data.append(line[0].strip())
    f.close()
    return data

    Loads data from a csv file and returns the corresponding list. See provided input files for format convention.

    :param filename: csv file name.

    :param skip_first_line: if True, the first line is not read. Default value: False.

    :param ignore_first_column: if True, the first column is ignored. Default value: False.

    :param data_type: either 'points' or 'words'.

    :return: a list of data.
    
Loads data from a csv file and returns the corresponding list. See provided input files for format convention.
Loads data from a csv file and returns the corresponding list . See provided input files for format convention .
def read_data(filename, skip_first_line=False, ignore_first_column=False, data_type='points'):
    f = open(filename, 'r')
    if skip_first_line:
        f.readline()
    data = []
    if data_type == 'points':
        for line in f:
            line = line.split(",")
            line[1:] = [float(x) for x in line[1:]]
            if ignore_first_column:
                line = line[1:]
            data.append(tuple(line))
    else:
        for line in f:
            line = line.split(' ')
            data.append(line[0].strip())
    f.close()
    return data
def read_data ( filename , skip_first_line = False , ignore_first_column = False , data_type = 'points' ) : f = open ( filename , 'r' ) if skip_first_line : f . readline ( ) data = [ ] if data_type == 'points' : for line in f : line = line . split ( "," ) line [ 1 : ] = [ float ( x ) for x in line [ 1 : ] ] if ignore_first_column : line = line [ 1 : ] data . append ( tuple ( line ) ) else : for line in f : line = line . split ( ' ' ) data . append ( line [ 0 ] . strip ( ) ) f . close ( ) return data
Loads data from a csv file and returns the corresponding list.
Loads data from a csv file and returns the corresponding list .
"""
    Loads data from a csv file and returns the corresponding list. See provided input files for format convention.

    :param filename: csv file name.

    :param skip_first_line: if True, the first line is not read. Default value: False.

    :param ignore_first_column: if True, the first column is ignored. Default value: False.

    :param data_type: either 'points' or 'words'.

    :return: a list of data.
    """
a list of data.
a list of data .
filename
csv file name.
csv file name .
skip_first_line
if True, the first line is not read. Default value: False.
if True the first line is not read . Default value : False .
ignore_first_column
if True, the first column is ignored. Default value: False.
if True the first column is ignored . Default value : False .
data_type
either 'points' or 'words'.
either ' points ' or ' words ' .