scipy.sparse.csgraph.

reverse_cuthill_mckee#

scipy.sparse.csgraph.reverse_cuthill_mckee(graph, symmetric_mode=False)#

返回排列陣列,該陣列以反向 Cuthill-McKee 順序排列稀疏 CSR 或 CSC 矩陣。

預設情況下,symmetric_mode=False,假設輸入矩陣不是對稱的,並且作用於矩陣 A+A.T。如果您保證矩陣在結構上是對稱的(矩陣元素的值無關緊要),則設定 symmetric_mode=True

參數:
graph稀疏陣列或矩陣

以 CSC 或 CSR 稀疏陣列或矩陣格式輸入稀疏矩陣。

symmetric_modebool,可選

輸入矩陣是否保證為對稱。

返回:
permndarray

排列後的行和列索引陣列。

註解

在版本 0.15.0 中新增。

參考文獻

E. Cuthill 和 J. McKee,“Reducing the Bandwidth of Sparse Symmetric Matrices”,ACM ‘69 Proceedings of the 1969 24th national conference,(1969)。

範例

>>> from scipy.sparse import csr_array
>>> from scipy.sparse.csgraph import reverse_cuthill_mckee
>>> graph = [
... [0, 1, 2, 0],
... [0, 0, 0, 1],
... [2, 0, 0, 3],
... [0, 0, 0, 0]
... ]
>>> graph = csr_array(graph)
>>> print(graph)
<Compressed Sparse Row sparse array of dtype 'int64'
    with 5 stored elements and shape (4, 4)>
    Coords  Values
    (0, 1)  1
    (0, 2)  2
    (1, 3)  1
    (2, 0)  2
    (2, 3)  3
>>> reverse_cuthill_mckee(graph)
array([3, 2, 1, 0], dtype=int32)