graph.py¶
Utilities for creating and interacting with graph objects.
author: Stefan McCabe (stefanmccabe at gmail dot com)
Submitted as part of the 2019 NetSI Collabathon.

netrd.utilities.graph.
create_graph
(A, create_using=None, remove_self_loops=True)[source]¶ Flexibly creating a networkx graph from a numpy array.
 Parameters:
 A (np.ndarray)
A numpy array.
 create_using (nx.Graph or None)
Create the graph using a specific networkx graph. Can be used for forcing an asymmetric matrix to create an undirected graph, for example.
 remove_self_loops (bool)
If True, remove the diagonal of the matrix before creating the graph object.
 Returns:
 G
A graph, typically a nx.Graph or nx.DiGraph.

netrd.utilities.graph.
ensure_undirected
(G)[source]¶ Ensure the graph G is undirected.
If it is not, coerce it to undirected and warn the user.
 Parameters:
 G (networkx graph)
The graph to be checked
 Returns:
 G (nx.Graph)
Undirected version of the input graph

netrd.utilities.graph.
ensure_unweighted
(G)[source]¶ Ensure the graph G is unweighted.
If it is not, coerce it to unweighted and warn the user.
 Parameters:
 G (networkx graph)
The graph to be checked
 Returns:
 G (nx.Graph)
Unweighted version of the input graph