to_numpy_recarray¶
- to_numpy_recarray(G, nodelist=None, dtype=None, order=None)[source]¶
Returns the graph adjacency matrix as a NumPy recarray.
Deprecated since version 2.7:
to_numpy_recarray
is deprecated and will be removed in NetworkX 3.0. Usenx.to_numpy_array(G, dtype=dtype, weight=None).view(np.recarray)
instead.- Parameters
- Ggraph
The NetworkX graph used to construct the NumPy recarray.
- nodelistlist, optional
The rows and columns are ordered according to the nodes in
nodelist
. Ifnodelist
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. The default is
dtype([("weight", float)])
.- 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
- MNumPy recarray
The graph with specified edge data as a Numpy recarray
Notes
When
nodelist
does not contain every node inG
, the adjacency matrix is built from the subgraph ofG
that is induced by the nodes innodelist
.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]]