本文整理汇总了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
示例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
示例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.
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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())
示例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
示例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)
示例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
示例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)