當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python SciPy csgraph.reverse_cuthill_mckee用法及代碼示例

本文簡要介紹 python 語言中 scipy.sparse.csgraph.reverse_cuthill_mckee 的用法。

用法:

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

返回按 Reverse-Cuthill McKee 順序對稀疏 CSR 或 CSC 矩陣進行排序的排列數組。

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

參數

graph 稀疏矩陣

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

symmetric_mode 布爾型,可選

輸入矩陣是否保證對稱。

返回

perm ndarray

排列的行和列索引數組。

注意

參考

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)

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.sparse.csgraph.reverse_cuthill_mckee。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。