主页
Python
SciPy 图表
demo_scipy_graphs_connected_components
运行 ❯
×
更改方向
保存代码
更改主题
import numpy as np from scipy.sparse.csgraph import connected_components from scipy.sparse import csr_matrix arr = np.array([ [0, 1, 2], [1, 0, 0], [2, 0, 0] ]) newarr = csr_matrix(arr) print(connected_components(newarr))
(1, array([0, 0, 0], dtype=int32))