当前位置: 首页>>代码示例>>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;未经允许,请勿转载。