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


Python networkx.from_edgelist方法代碼示例

本文整理匯總了Python中networkx.from_edgelist方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.from_edgelist方法的具體用法?Python networkx.from_edgelist怎麽用?Python networkx.from_edgelist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.from_edgelist方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_inverse_degree_matrix

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def create_inverse_degree_matrix(edges):
    """
    Creating an inverse degree matrix from an edge list.
    :param edges: Edge list.
    :return D_1: Inverse degree matrix.
    """
    graph = nx.from_edgelist(edges)
    ind = range(len(graph.nodes()))
    degs = [1.0/graph.degree(node) for node in range(graph.number_of_nodes())]

    D_1 = sparse.coo_matrix((degs, (ind, ind)),
                            shape=(graph.number_of_nodes(),
                            graph.number_of_nodes()),
                            dtype=np.float32)

    return D_1 
開發者ID:benedekrozemberczki,項目名稱:GraRep,代碼行數:18,代碼來源:utils.py

示例2: read_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def read_graph(edge_path, order):
    """
    Method to read graph and create a target matrix by summing adjacency matrix powers.
    :param edge_path: Path to the ege list.
    :param order: Order of approximations.
    :return out_A: Target matrix.
    """
    print("Target matrix creation started.")
    graph = nx.from_edgelist(pd.read_csv(edge_path).values.tolist())
    A = normalize_adjacency(graph)
    if order > 1:
        powered_A, out_A = A, A
        for _ in tqdm(range(order-1)):
            powered_A = powered_A.dot(A)
            out_A = out_A + powered_A
    else:
        out_A = A
    print("Factorization started.")
    return out_A 
開發者ID:benedekrozemberczki,項目名稱:FSCNMF,代碼行數:21,代碼來源:helpers.py

示例3: test_device_stuff

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def test_device_stuff():
    topo = nx.from_edgelist([(0, 4), (0, 99)])
    qc = QuantumComputer(
        name="testy!",
        qam=None,  # not necessary for this test
        device=NxDevice(topo),
        compiler=DummyCompiler(),
    )
    assert nx.is_isomorphic(qc.qubit_topology(), topo)

    isa = qc.get_isa(twoq_type="CPHASE")
    assert isa.edges[0].type == "CPHASE"
    assert isa.edges[0].targets == (0, 4)


# We sometimes narrowly miss the np.mean(parity) < 0.15 assertion, below. Alternatively, that upper
# bound could be relaxed. 
開發者ID:rigetti,項目名稱:pyquil,代碼行數:19,代碼來源:test_quantum_computer.py

示例4: read_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def read_graph(edge_path, order):
    """
    Method to read graph and create a target matrix with pooled
    adjacency matrix powers up to the order.
    :param edge_path: Path to the ege list.
    :param order: Order of approximations.
    :return out_A: Target matrix.
    """
    print("Target matrix creation started.")
    graph = nx.from_edgelist(pd.read_csv(edge_path).values.tolist())
    A = normalize_adjacency(graph)
    if order > 1:
        powered_A, out_A = A, A
        for _ in tqdm(range(order-1)):
            powered_A = powered_A.dot(A)
            out_A = out_A + powered_A
    else:
        out_A = A
    print("Factorization started.")
    return out_A 
開發者ID:benedekrozemberczki,項目名稱:TENE,代碼行數:22,代碼來源:helpers.py

示例5: dataset_reader

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def dataset_reader(path):
    """
    Function to read the graph and features from a json file.
    :param path: The path to the graph json.
    :return graph: The graph object.
    :return features: Features hash table.
    :return name: Name of the graph.
    """
    name = path.strip(".json").split("/")[-1]
    data = json.load(open(path))
    graph = nx.from_edgelist(data["edges"])

    if "features" in data.keys():
        features = data["features"]
    else:
        features = nx.degree(graph)

    features = {int(k): v for k, v in features.items()}
    return graph, features, name 
開發者ID:benedekrozemberczki,項目名稱:graph2vec,代碼行數:21,代碼來源:graph2vec.py

示例6: from_edgelist

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def from_edgelist(edgelist,create_using=None):
    """Return a graph from a list of edges.

    Parameters
    ----------
    edgelist : list or iterator
      Edge tuples

    create_using : NetworkX graph
       Use specified graph for result.  Otherwise a new graph is created.

    Examples
    --------
    >>> edgelist= [(0,1)] # single edge (0,1)
    >>> G=nx.from_edgelist(edgelist)

    or
    >>> G=nx.Graph(edgelist) # use Graph constructor

    """
    G=_prep_create_using(create_using)
    G.add_edges_from(edgelist)
    return G 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:25,代碼來源:convert.py

示例7: from_edgelist

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def from_edgelist(edgelist, create_using=None):
    """Returns a graph from a list of edges.

    Parameters
    ----------
    edgelist : list or iterator
      Edge tuples

    create_using : NetworkX graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.

    Examples
    --------
    >>> edgelist = [(0, 1)] # single edge (0,1)
    >>> G = nx.from_edgelist(edgelist)

    or

    >>> G = nx.Graph(edgelist) # use Graph constructor

    """
    G = nx.empty_graph(0, create_using)
    G.add_edges_from(edgelist)
    return G 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:26,代碼來源:convert.py

示例8: from_edgelist

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def from_edgelist(edgelist, create_using=None):
    """Return a graph from a list of edges.

    Parameters
    ----------
    edgelist : list or iterator
      Edge tuples

    create_using : NetworkX graph
       Use specified graph for result.  Otherwise a new graph is created.

    Examples
    --------
    >>> edgelist = [(0, 1)] # single edge (0,1)
    >>> G = nx.from_edgelist(edgelist)

    or

    >>> G = nx.Graph(edgelist) # use Graph constructor

    """
    G = _prep_create_using(create_using)
    G.add_edges_from(edgelist)
    return G 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:26,代碼來源:convert.py

示例9: PyGGraph_to_nx

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def PyGGraph_to_nx(data):
    edges = list(zip(data.edge_index[0, :].tolist(), data.edge_index[1, :].tolist()))
    g = nx.from_edgelist(edges)
    g.add_nodes_from(range(len(data.x)))  # in case some nodes are isolated
    # transform r back to rating label
    edge_types = {(u, v): data.edge_type[i].item() for i, (u, v) in enumerate(edges)}  
    nx.set_edge_attributes(g, name='type', values=edge_types)
    node_types = dict(zip(range(data.num_nodes), torch.argmax(data.x, 1).tolist()))
    nx.set_node_attributes(g, name='type', values=node_types)
    g.graph['rating'] = data.y.item()
    return g 
開發者ID:muhanzhang,項目名稱:IGMC,代碼行數:13,代碼來源:util_functions.py

示例10: read_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [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

示例11: graph_reader

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def graph_reader(path):
    """
    Reading the edgelist.
    :param path: Edge list path.
    :return : NetworkX graph.
    """
    return nx.from_edgelist(pd.read_csv(path).values.tolist()) 
開發者ID:benedekrozemberczki,項目名稱:ASNE,代碼行數:9,代碼來源:utils.py

示例12: graph_reader

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [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

示例13: _create_persona_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def _create_persona_graph(self):
        """
        Create a persona graph using the egonet components.
        """
        print("Creating the persona graph.")
        self.persona_graph_edges = [self._get_new_edge_ids(e) for e in tqdm(self.graph.edges())]
        self.persona_graph = nx.from_edgelist(self.persona_graph_edges) 
開發者ID:benedekrozemberczki,項目名稱:EgoSplitting,代碼行數:9,代碼來源:ego_splitter.py

示例14: get_graphs

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def get_graphs(self):
        r"""Getting the graphs.

        Return types:
            * **graphs** *(List of NetworkX graphs)* - Graphs of interest.
        """
        graphs = self._dataset_reader("graphs.json")
        graphs = json.loads(graphs.decode())
        graphs = [nx.from_edgelist(graphs[str(i)]) for i in range(len(graphs))]
        return graphs 
開發者ID:benedekrozemberczki,項目名稱:karateclub,代碼行數:12,代碼來源:dataset_reader.py

示例15: _calculate_motifs

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_edgelist [as 別名]
def _calculate_motifs(self):
        """
        Enumerating pairwise motif counts.
        """
        edges = [e for e in self._graph.edges() if self._overlap(e[0], e[1]) >= self.cutoff]
        self._motif_graph = nx.from_edgelist(edges) 
開發者ID:benedekrozemberczki,項目名稱:karateclub,代碼行數:8,代碼來源:edmot.py


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