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
weight : string or None optional (default=’weight’)
|
---|---|
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 does not contain every node in , the matrix is built from the subgraph of that is induced by the nodes in .
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.]])