本文整理匯總了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)