Warning
This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
to_numpy_recarray¶

to_numpy_recarray
(G, nodelist=None, dtype=[('weight', <type 'float'>)], order=None)[source]¶ Return the graph adjacency matrix as a NumPy recarray.
Parameters:  G (graph) – The NetworkX graph used to construct the NumPy matrix.
 nodelist (list, optional) – The rows and columns are ordered according to the nodes in . If is None, then the ordering is produced by G.nodes().
 dtype (NumPy datatype, optional) – A valid NumPy named dtype used to initialize the NumPy recarray. The data type names are assumed to be keys in the graph edge attribute dictionary.
 order ({‘C’, ‘F’}, optional) – Whether to store multidimensional data in C or Fortrancontiguous (row or columnwise) order in memory. If None, then the NumPy default is used.
Returns: M – The graph with specified edge data as a Numpy recarray
Return type: NumPy recarray
Notes
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.Graph() >>> G.add_edge(1,2,weight=7.0,cost=5) >>> A=nx.to_numpy_recarray(G,dtype=[('weight',float),('cost',int)]) >>> print(A.weight) [[ 0. 7.] [ 7. 0.]] >>> print(A.cost) [[0 5] [5 0]]