to_numpy_recarray#
- to_numpy_recarray(G, nodelist=None, dtype=None, order=None)[源代码]#
以numpy recarray形式返回图形邻接矩阵。
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.- 参数
- G图表
用于构建NumPy重新数组的网络X图。
- nodelist列表,可选
行和列根据中的节点进行排序
nodelist
。如果nodelist
为NONE,则排序由G.Nodes()生成。- dtypeNumPy数据类型,可选
用于初始化NumPy重新数组的名为dtype的有效NumPy。假定数据类型名称是图边属性字典中的关键字。默认为
dtype([("weight", float)])
。- order{‘C’,‘F’},可选
在内存中是以C顺序存储多维数据,还是按Fortran顺序(按行或按列)存储多维数据。如果为None,则使用NumPy默认值。
- 返回
- MNumPy重新数组
将指定的边数据表示为块重数组的图
笔记
什么时候?
nodelist
不包含中的每个节点G
,邻接矩阵是从G
这是由中的节点引起的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]]