本文整理汇总了Python中networkx.selfloop_edges方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.selfloop_edges方法的具体用法?Python networkx.selfloop_edges怎么用?Python networkx.selfloop_edges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.selfloop_edges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def fit(self, graph):
"""
Fitting a GraphWave model.
Arg types:
* **graph** *(NetworkX graph)* - The graph to be embedded.
"""
self._set_seed()
self._check_graph(graph)
graph.remove_edges_from(nx.selfloop_edges(graph))
self._create_evaluation_points()
self._check_size(graph)
self._G = pygsp.graphs.Graph(nx.adjacency_matrix(graph))
if self.mechanism == "exact":
self._exact_structural_wavelet_embedding()
elif self.mechanism == "approximate":
self._approximate_structural_wavelet_embedding()
else:
raise NameError("Unknown method.")
示例2: nodes_with_selfloops
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def nodes_with_selfloops(G):
"""Returns an iterator over nodes with self loops.
A node with a self loop has an edge with both ends adjacent
to that node.
Returns
-------
nodelist : iterator
A iterator over nodes with self loops.
See Also
--------
selfloop_edges, number_of_selfloops
Examples
--------
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge(1, 1)
>>> G.add_edge(1, 2)
>>> list(nx.nodes_with_selfloops(G))
[1]
"""
return (n for n, nbrs in G.adj.items() if n in nbrs)
示例3: number_of_selfloops
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def number_of_selfloops(G):
"""Returns the number of selfloop edges.
A selfloop edge has the same node at both ends.
Returns
-------
nloops : int
The number of selfloops.
See Also
--------
nodes_with_selfloops, selfloop_edges
Examples
--------
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge(1, 1)
>>> G.add_edge(1, 2)
>>> nx.number_of_selfloops(G)
1
"""
return sum(1 for _ in nx.selfloop_edges(G))
示例4: test_deprecated
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def test_deprecated():
# for backwards compatibility with 1.x, will be removed for 3.x
G = nx.complete_graph(3)
assert_equal(G.node, {0: {}, 1: {}, 2: {}})
G = nx.DiGraph()
G.add_path([3, 4])
assert_equal(G.adj, {3: {4: {}}, 4: {}})
G = nx.DiGraph()
G.add_cycle([3, 4, 5])
assert_equal(G.adj, {3: {4: {}}, 4: {5: {}}, 5: {3: {}}})
G = nx.DiGraph()
G.add_star([3, 4, 5])
assert_equal(G.adj, {3: {4: {}, 5: {}}, 4: {}, 5: {}})
G = nx.DiGraph([(0, 0), (0, 1), (1, 2)])
assert_equal(G.number_of_selfloops(), 1)
assert_equal(list(G.nodes_with_selfloops()), [0])
assert_equal(list(G.selfloop_edges()), [(0, 0)])
示例5: number_of_selfloops
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def number_of_selfloops(G):
"""Return the number of selfloop edges.
A selfloop edge has the same node at both ends.
Returns
-------
nloops : int
The number of selfloops.
See Also
--------
nodes_with_selfloops, selfloop_edges
Examples
--------
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge(1, 1)
>>> G.add_edge(1, 2)
>>> nx.number_of_selfloops(G)
1
"""
return sum(1 for _ in nx.selfloop_edges(G))
示例6: read_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def read_graph(args):
"""
Method to read graph and create a target matrix with adjacency matrix powers.
:param args: Arguments object.
:return powered_P: Target matrix.
"""
print("\nTarget matrix creation started.\n")
graph = nx.from_edgelist(pd.read_csv(args.edge_path).values.tolist())
graph.remove_edges_from(nx.selfloop_edges(graph))
P = normalize_adjacency(graph, args)
powered_P = P
if args.order > 1:
for _ in tqdm(range(args.order-1), desc="Adjacency matrix powers"):
powered_P = powered_P.dot(P)
return powered_P
示例7: graph_reader
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def graph_reader(path):
"""
Function to read the graph from the path.
:param path: Path to the edge list.
:return graph: NetworkX object returned.
"""
graph = nx.from_edgelist(pd.read_csv(path).values.tolist())
graph.remove_edges_from(nx.selfloop_edges(graph))
return graph
示例8: fit
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def fit(self, graph):
"""
Fitting a Symm-NMF clustering model.
Arg types:
* **graph** *(NetworkX graph)* - The graph to be clustered.
"""
self._set_seed()
self._check_graph(graph)
graph.remove_edges_from(nx.selfloop_edges(graph))
A_hat = self._create_base_matrix(graph)
self._setup_embeddings(A_hat)
for step in range(self.iterations):
self._do_admm_update(A_hat)
示例9: _calculate_netlsd
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def _calculate_netlsd(self, graph):
"""
Calculating the features of a graph.
Arg types:
* **graph** *(NetworkX graph)* - A graph to be embedded.
Return types:
* **hist** *(Numpy array)* - The embedding of a single graph.
"""
graph.remove_edges_from(nx.selfloop_edges(graph))
laplacian = sps.coo_matrix(nx.normalized_laplacian_matrix(graph, nodelist = range(graph.number_of_nodes())), dtype=np.float32)
eigen_values = self._calculate_eigenvalues(laplacian)
heat_kernel_trace = self._calculate_heat_kernel_trace(eigen_values)
return heat_kernel_trace
示例10: read_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def read_graph(graph_path):
"""
Method to read graph and create a target matrix with pooled adjacency matrix powers.
:param args: Arguments object.
:return graph: graph.
"""
print("\nTarget matrix creation started.\n")
graph = nx.from_edgelist(pd.read_csv(graph_path).values.tolist())
graph.remove_edges_from(nx.selfloop_edges(graph))
return graph
示例11: load_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def load_graph(graph_path):
"""
Reading a NetworkX graph.
:param graph_path: Path to the edge list.
:return graph: NetworkX object.
"""
data = pd.read_csv(graph_path)
edges = data.values.tolist()
edges = [[int(edge[0]), int(edge[1])] for edge in edges]
graph = nx.from_edgelist(edges)
graph.remove_edges_from(nx.selfloop_edges(graph))
return graph
示例12: graph_reader
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def graph_reader(path):
"""
Function to create an NX graph object.
:param path: Path to the edge list csv.
:return graph: NetworkX graph.
"""
graph = nx.from_edgelist(pd.read_csv(path).values.tolist())
graph.remove_edges_from(nx.selfloop_edges(graph))
return graph
示例13: graph_reader
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def graph_reader(path):
"""
Function to read the graph from the path.
:param path: Path to the edge list.
:return graph: NetworkX object returned.
"""
graph = nx.from_edgelist(pd.read_csv(path).values.tolist())
graph.remove_edges_from(list(nx.selfloop_edges(graph)))
return graph
示例14: read_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def read_graph(settings):
"""
Reading the edge list from the path and returning the networkx graph object.
:param path: Path to the edge list.
:return graph: Graph from edge list.
"""
if settings.edgelist_input:
graph = nx.read_edgelist(settings.input)
else:
edge_list = pd.read_csv(settings.input).values.tolist()
graph = nx.from_edgelist(edge_list)
graph.remove_edges_from(nx.selfloop_edges(graph))
return graph
示例15: selfloop_edges
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import selfloop_edges [as 别名]
def selfloop_edges(self, data=False, keys=False, default=None):
msg = "selfloop_edges is deprecated. Use nx.selfloop_edges instead."
warnings.warn(msg, DeprecationWarning)
return nx.selfloop_edges(self, data, keys, default)
# Done with backward compatibility methods for 1.x