nocad.io.from_networkx#
- nocad.io.from_networkx(G, weight=None, nodes=None)[source]#
Network of state variables from a NetworkX graph.
- Parameters:
- G
networkx.DiGraph(anundirectedgraphisreadassymmetric) - weight
str,optional Edge attribute with the numeric values of \(a_{ij}\) (structure only if None).
- nodes
list,optional Node order (default:
G.nodes()).
- G
- Returns:
- net
Bunchwithadj(sparseadjacency),labels(nodenamesasstrings), nodes(original node objects),node_data(DataFrame of node attributes),drivers/sensors(from booleandriver/sensorattributes, if any) andweights(sparse weighted adjacency ifweightis given).
- net
Examples
>>> import networkx as nx >>> G = nx.DiGraph([("tank1", "tank2"), ("tank2", "tank2")]) >>> net = from_networkx(G) >>> net.labels, net.adj.toarray().astype(int).tolist() (['tank1', 'tank2'], [[0, 1], [0, 1]])