def create_graph_from_adjacency_matrix(adjacency_matrix):
if is_adjacency_matrix_symmetric(adjacency_matrix):<EOL><INDENT>graph = UndirectedGraph()<EOL><DEDENT>else:<EOL><INDENT>graph = DirectedGraph()<EOL><DEDENT>node_column_mapping = []<EOL>num_columns = len(adjacency_matrix)<EOL>for _ in range(num_columns):<EOL><INDENT>node_id = graph.new_node()<EOL>node_column_mapping.append(node_id)<EOL><DEDENT>for j in range(num_columns):<EOL><INDENT>for i in range(num_columns):<EOL><INDENT>if adjacency_matrix[j][i]:<EOL><INDENT>jnode_id = node_column_mapping[j]<EOL>inode_id = node_column_mapping[i]<EOL>graph.new_edge(inode_id, jnode_id)<EOL><DEDENT><DEDENT><DEDENT>return (graph, node_column_mapping)<EOL>
Generates a graph from an adjacency matrix specification.
       Returns a tuple containing the graph and a list-mapping of node ids to matrix column indices.

       The graph will be an UndirectedGraph if the provided adjacency matrix is symmetric.
       The graph will be a DirectedGraph if the provided adjacency matrix is not symmetric.
       Ref: http://mathworld.wolfram.com/AdjacencyMatrix.html