<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import numpy as np <EOL> class Graph ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , adjacency_matix , node_labels = None , edge_labels = None ) : <EOL> self . adjacency_matix = adjacency_matix <EOL> self . node_labels = node_labels <EOL> self . edge_labels = edge_labels <EOL> def graphs_to_adjacency_lists ( data ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if data . ndim == <NUM_LIT:3> : <EOL> return np . array ( data ) <EOL> except Exception , exc : <EOL> try : <EOL> return np . array ( [ G . adjacency_matix for G in data ] ) <EOL> except Exception , exc : <EOL> return np . array ( data ) <EOL> def relabel ( data , data_2 ) : <EOL> """<STR_LIT>""" <EOL> len_first = len ( data ) <EOL> for d in data_2 : <EOL> data . append ( d ) <EOL> data = np . array ( data ) <EOL> label_set = dict ( ) <EOL> for node_labels in data : <EOL> for label in node_labels : <EOL> if label not in label_set . keys ( ) : <EOL> llen = len ( label_set ) <EOL> label_set [ label ] = llen <EOL> res = [ ] <EOL> for i , node_labels in enumerate ( data ) : <EOL> res . append ( [ ] ) <EOL> for j , label in enumerate ( node_labels ) : <EOL> res [ i ] . append ( label_set [ label ] + <NUM_LIT:1> ) <EOL> return res [ : len_first ] , res [ len_first : ] , len ( label_set ) </s>
