This documents the development version of NetworkX. Documentation for the current release can be found here.


to_numpy_recarray(G, nodelist=None, dtype=None, order=None)[source]

Returns the graph adjacency matrix as a NumPy recarray.


The NetworkX graph used to construct the NumPy recarray.

nodelistlist, optional

The rows and columns are ordered according to the nodes in nodelist. If nodelist is None, then the ordering is produced by G.nodes().

dtypeNumPy data-type, 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 Fortran-contiguous (row- or column-wise) order in memory. If None, then the NumPy default is used.

MNumPy recarray

The graph with specified edge data as a Numpy recarray


When nodelist does not contain every node in G, the adjacency matrix is built from the subgraph of G that is induced by the nodes in nodelist.


>>> 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]]