scipy.sparse.csgraph.
structural_rank#
- scipy.sparse.csgraph.structural_rank(graph)#
計算具有給定稀疏模式的圖形(矩陣)的結構秩。
矩陣的結構秩是對應二分圖的最大橫貫中的條目數,並且是矩陣數值秩的上限。如果可以置換元素以使對角線無零,則圖形具有完整結構秩。
在 0.19.0 版本中新增。
- 參數:
- graph稀疏陣列或矩陣
輸入稀疏陣列。
- 回傳值:
- rank整數
稀疏圖形的結構秩。
參考文獻
[1]I. S. Duff, “Computing the Structural Index”, SIAM J. Alg. Disc. Meth., Vol. 7, 594 (1986)。
範例
>>> from scipy.sparse import csr_array >>> 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_array(graph) >>> print(graph) <Compressed Sparse Row sparse array 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