#

Note

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

#

networkx.convert_matrix.to_numpy_recarray

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

Returns the graph adjacency matrix as a NumPy recarray.

Parameters
  • G (graph) – The NetworkX graph used to construct the NumPy recarray.

  • nodelist (list, 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().

  • dtype (NumPy 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.

Returns

M – The graph with specified edge data as a Numpy recarray

Return type

NumPy recarray

Notes

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.

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