Return the graph adjacency matrix as a NumPy matrix.
Parameters : | G : graph
nodelist : list, optional
dtype : NumPy data type, optional
order : {‘C’, ‘F’}, optional
multigraph_weight : {sum, min, max}, optional
|
---|---|
Returns : | M : NumPy matrix
|
See also
Notes
The matrix entries are assigned with ‘weight’ edge attribute. When an edge does not have the ‘weight’ attribute, the value of the entry is 1. For multiple edges, the values of the entries are the sums of the edge attributes for each edge.
When nodelist does not contain every node in G, the matrix is built from the subgraph of G that is induced by the nodes in nodelist.
Examples
>>> G = nx.MultiDiGraph()
>>> G.add_edge(0,1,weight=2)
>>> G.add_edge(1,0)
>>> G.add_edge(2,2,weight=3)
>>> G.add_edge(2,2)
>>> nx.to_numpy_matrix(G, nodelist=[0,1,2])
matrix([[ 0., 2., 0.],
[ 1., 0., 0.],
[ 0., 0., 4.]])