scipy.sparse.csgraph.csgraph_from_dense¶
- scipy.sparse.csgraph.csgraph_from_dense(graph, null_value=0, nan_null=True, infinity_null=True)¶
从稠密矩阵构造CSR格式的稀疏图。
0.11.0 新版功能.
- 参数
- grapharray_like
输入图形。形状应为(n_Nodes,n_Nodes)。
- null_value浮动或无(可选)
值,该值表示图形中的非边。默认值为零。
- infinity_null布尔尔
如果为True(默认值),则无限个条目(正数和负数)将被视为空边。
- nan_null布尔尔
如果为True(默认值),则NaN条目将被视为非边
- 退货
- csgraphcsr_matrix
图的压缩稀疏表示,
示例
>>> from scipy.sparse.csgraph import csgraph_from_dense
>>> graph = [ ... [0, 1, 2, 0], ... [0, 0, 0, 1], ... [0, 0, 0, 3], ... [0, 0, 0, 0] ... ]
>>> csgraph_from_dense(graph) <4x4 sparse matrix of type '<class 'numpy.float64'>' with 4 stored elements in Compressed Sparse Row format>