本文整理汇总了Python中networkx.number_weakly_connected_components方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.number_weakly_connected_components方法的具体用法?Python networkx.number_weakly_connected_components怎么用?Python networkx.number_weakly_connected_components使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.number_weakly_connected_components方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _sanity_check
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_weakly_connected_components [as 别名]
def _sanity_check(G):
r"""
Helper function that checks if the input graphs contains a single connected component. Raises an error if not.
Parameters
----------
G : graph
A NetworkX graph
Raises
------
ValueError
If the graph has more than one (weakly) connected component.
"""
# Compute the number of connected components
if G.is_directed():
num_ccs = nx.number_weakly_connected_components(G)
else:
num_ccs = nx.number_connected_components(G)
# Rise an error if more than one CC exists
if num_ccs != 1:
raise ValueError("Input graph should contain one (weakly) connected component. "
"This graph contains: " + str(num_ccs))
示例2: list
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_weakly_connected_components [as 别名]
def list(self) -> List[Tuple[str, float]]:
"""Return a list of tuples that summarize the graph."""
number_nodes = self.graph.number_of_nodes()
return [
('Name', self.graph.name),
('Version', self.graph.version),
('Number of Nodes', number_nodes),
('Number of Namespaces', len(self.graph.count.namespaces())),
('Number of Edges', self.graph.number_of_edges()),
('Number of Annotations', len(self.graph.count.annotations())),
('Number of Citations', self.graph.number_of_citations()),
('Number of Authors', self.graph.number_of_authors()),
('Network Density', '{:.2E}'.format(nx.density(self.graph))),
('Number of Components', nx.number_weakly_connected_components(self.graph)),
('Number of Warnings', self.graph.number_of_warnings()),
]
示例3: component_nb
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_weakly_connected_components [as 别名]
def component_nb(self) -> int:
"""Return the number of independent components that this
DAGCircuit can be split into."""
return nx.number_weakly_connected_components(self.graph)
示例4: test_number_weakly_connected_components
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_weakly_connected_components [as 别名]
def test_number_weakly_connected_components(self):
for G, C in self.gc:
U = G.to_undirected()
w = nx.number_weakly_connected_components(G)
c = nx.number_connected_components(U)
assert_equal(w, c)
示例5: test_connected_raise
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_weakly_connected_components [as 别名]
def test_connected_raise(self):
G=nx.Graph()
assert_raises(NetworkXNotImplemented,nx.weakly_connected_components, G)
assert_raises(NetworkXNotImplemented,nx.number_weakly_connected_components, G)
assert_raises(NetworkXNotImplemented,nx.weakly_connected_component_subgraphs, G)
assert_raises(NetworkXNotImplemented,nx.is_weakly_connected, G)
示例6: test_number_weakly_connected_components
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_weakly_connected_components [as 别名]
def test_number_weakly_connected_components(self):
for G, C in self.gc:
U = G.to_undirected()
w = nx.number_weakly_connected_components(G)
c = nx.number_connected_components(U)
assert_equal(w, c)
# deprecated
示例7: test_null_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_weakly_connected_components [as 别名]
def test_null_graph(self):
G = nx.DiGraph()
assert_equal(list(nx.weakly_connected_components(G)), [])
assert_equal(nx.number_weakly_connected_components(G), 0)
assert_raises(nx.NetworkXPointlessConcept, nx.is_weakly_connected, G)
示例8: test_connected_raise
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_weakly_connected_components [as 别名]
def test_connected_raise(self):
G = nx.Graph()
assert_raises(NetworkXNotImplemented, nx.weakly_connected_components, G)
assert_raises(NetworkXNotImplemented, nx.number_weakly_connected_components, G)
assert_raises(NetworkXNotImplemented, nx.is_weakly_connected, G)
# deprecated
assert_raises(NetworkXNotImplemented, nx.weakly_connected_component_subgraphs, G)