當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.selfloop_edges方法代碼示例

本文整理匯總了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.") 
開發者ID:benedekrozemberczki,項目名稱:karateclub,代碼行數:22,代碼來源:graphwave.py

示例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) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:27,代碼來源:function.py

示例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)) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:25,代碼來源:function.py

示例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)]) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:23,代碼來源:test_graph.py

示例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)) 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:25,代碼來源:function.py

示例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 
開發者ID:benedekrozemberczki,項目名稱:BANE,代碼行數:17,代碼來源:utils.py

示例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 
開發者ID:benedekrozemberczki,項目名稱:EgoSplitting,代碼行數:11,代碼來源:utils.py

示例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) 
開發者ID:benedekrozemberczki,項目名稱:karateclub,代碼行數:16,代碼來源:symmnmf.py

示例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 
開發者ID:benedekrozemberczki,項目名稱:karateclub,代碼行數:17,代碼來源:netlsd.py

示例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 
開發者ID:benedekrozemberczki,項目名稱:AttentionWalk,代碼行數:12,代碼來源:utils.py

示例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 
開發者ID:benedekrozemberczki,項目名稱:MUSAE,代碼行數:14,代碼來源:utils.py

示例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 
開發者ID:benedekrozemberczki,項目名稱:GraphWaveletNeuralNetwork,代碼行數:11,代碼來源:utils.py

示例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 
開發者ID:benedekrozemberczki,項目名稱:MixHop-and-N-GCN,代碼行數:11,代碼來源:utils.py

示例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 
開發者ID:benedekrozemberczki,項目名稱:GraphWaveMachine,代碼行數:15,代碼來源:main.py

示例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 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:7,代碼來源:graph.py


注:本文中的networkx.selfloop_edges方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。