def read_matlab_features(array_paths, number_of_nodes, dimensionality):
    """
    Returns a sparse feature matrix as calculated by a Matlab routine.
    """
    # Read the data array
    file_row_gen = get_file_row_generator(array_paths[0], "\t")
    data = list()
    append_data = data.append
    for file_row in file_row_gen:
        append_data(float(file_row[0]))

    # Read the row array
    file_row_gen = get_file_row_generator(array_paths[1], "\t")
    row = list()
    append_row = row.append
    for file_row in file_row_gen:
        append_row(int(float(file_row[0])))

    # Read the data array
    file_row_gen = get_file_row_generator(array_paths[2], "\t")
    col = list()
    append_col = col.append
    for file_row in file_row_gen:
        append_col(int(float(file_row[0])))

    data = np.array(data).astype(np.float64)
    row = np.array(row).astype(np.int64) - 1  # Due to Matlab numbering
    col = np.array(col).astype(np.int64) - 1  # Due to Matlab numbering

    print(np.max(row), np.min(row))
    print(np.max(col), np.min(col))

    # centroids_new = sparse.coo_matrix((data, (row, col)), shape=(number_of_nodes + 1, k))
    features = spsp.coo_matrix((data, (row, col)), shape=(number_of_nodes, dimensionality))

    return features
def read_matlab_features ( array_paths , number_of_nodes , dimensionality ) : file_row_gen = get_file_row_generator ( array_paths [ 0 ] , "\t" ) data = list ( ) append_data = data . append for file_row in file_row_gen : append_data ( float ( file_row [ 0 ] ) ) file_row_gen = get_file_row_generator ( array_paths [ 1 ] , "\t" ) row = list ( ) append_row = row . append for file_row in file_row_gen : append_row ( int ( float ( file_row [ 0 ] ) ) ) file_row_gen = get_file_row_generator ( array_paths [ 2 ] , "\t" ) col = list ( ) append_col = col . append for file_row in file_row_gen : append_col ( int ( float ( file_row [ 0 ] ) ) ) data = np . array ( data ) . astype ( np . float64 ) row = np . array ( row ) . astype ( np . int64 ) - 1 col = np . array ( col ) . astype ( np . int64 ) - 1 print ( np . max ( row ) , np . min ( row ) ) print ( np . max ( col ) , np . min ( col ) ) features = spsp . coo_matrix ( ( data , ( row , col ) ) , shape = ( number_of_nodes , dimensionality ) ) return features
Returns a sparse feature matrix as calculated by a Matlab routine.