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_mode布尔值,可选

是否保证输入矩阵是对称的。

退货
permndarray

排列的行和列索引的数组。

注意事项

0.15.0 新版功能.

参考文献

E.Cuthill和J.McKee,“减少稀疏对称矩阵的带宽”,ACM‘69“1969年第24届全国会议论文集”(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)
  (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)