scipy.sparse.csgraph.
reverse_cuthill_mckee#
- scipy.sparse.csgraph.reverse_cuthill_mckee(graph, symmetric_mode=False)#
返回一个稀疏CSR或CSC矩阵按Reverse-Cuthill McKee排序的排列数组。
默认情况下,假设
symmetric_mode=False
,即输入矩阵不是对称的,并且对矩阵A+A.T
进行操作。如果你确定矩阵在结构上是对称的(矩阵元素的值无关紧要),则设置symmetric_mode=True
。- 参数:
- 图稀疏矩阵
输入稀疏矩阵格式为CSC或CSR。
- 对称模式bool, 可选
输入矩阵是否保证为对称矩阵。
- 返回:
- 权限ndarray
置换行和列索引的数组。
注释
Added in version 0.15.0.
参考文献
E. Cuthill and J. McKee, “Reducing the Bandwidth of Sparse Symmetric Matrices”, ACM ‘69 Proceedings of the 1969 24th national conference, (1969).
示例
>>> from scipy.sparse import csr_matrix >>> 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_matrix(graph) >>> print(graph) <Compressed Sparse Row sparse matrix 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)