scipy.sparse.csgraph.
structural_rank#
- scipy.sparse.csgraph.structural_rank(graph)#
计算具有给定稀疏模式的图(矩阵)的结构秩。
矩阵的结构秩是对应二部图的最大横截中的条目数,并且是矩阵数值秩的上限。如果可以通过置换元素使对角线无零,则图具有满结构秩。
Added in version 0.19.0.
- 参数:
- 图稀疏矩阵
输入稀疏矩阵。
- 返回:
- 等级整数
稀疏图的结构等级。
参考文献
[1]I. S. Duff, “Computing the Structural Index”, SIAM J. Alg. Disc. Meth., Vol. 7, 594 (1986).
示例
>>> from scipy.sparse import csr_matrix >>> from scipy.sparse.csgraph import structural_rank
>>> graph = [ ... [0, 1, 2, 0], ... [1, 0, 0, 1], ... [2, 0, 0, 3], ... [0, 1, 3, 0] ... ] >>> graph = csr_matrix(graph) >>> print(graph) <Compressed Sparse Row sparse matrix of dtype 'int64' with 8 stored elements and shape (4, 4)> Coords Values (0, 1) 1 (0, 2) 2 (1, 0) 1 (1, 3) 1 (2, 0) 2 (2, 3) 3 (3, 1) 1 (3, 2) 3
>>> structural_rank(graph) 4