本文整理汇总了Python中networkx.to_networkx_graph函数的典型用法代码示例。如果您正苦于以下问题:Python to_networkx_graph函数的具体用法?Python to_networkx_graph怎么用?Python to_networkx_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_networkx_graph函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_graph_india
def test_graph_india():
A1 = np.loadtxt("adj_allVillageRelationships_vilno_1.csv", delimiter=",")
A2 = np.loadtxt("adj_allVillageRelationships_vilno_2.csv", delimiter=",")
G1 = nx.to_networkx_graph(A1)
G2 = nx.to_networkx_graph(A2)
basic_net_stats(G1)
basic_net_stats(G2)
plot_degree_distribution(G1)
plot_degree_distribution(G2)
plt.show()
开发者ID:piotrbla,项目名称:pyExamples,代码行数:10,代码来源:bird_tracking.py
示例2: _randomize
def _randomize(net, density=None):
n_nodes = len(net.nodes())
density = density or 1.0/n_nodes
max_attempts = 50
for attempt in xrange(max_attempts):
# create an random adjacency matrix with given density
adjmat = N.random.rand(n_nodes, n_nodes)
adjmat[adjmat >= (1.0-density)] = 1
adjmat[adjmat < 1] = 0
# add required edges
for src,dest in required_edges:
adjmat[src][dest] = 1
# remove prohibited edges
for src,dest in prohibited_edges:
adjmat[src][dest] = 0
# remove self-loop edges (those along the diagonal)
adjmat = N.invert(N.identity(n_nodes).astype(bool))*adjmat
# set the adjaceny matrix and check for acyclicity
net = nx.to_networkx_graph(adjmat, create_using=Network())
if net.is_acyclic():
return net
# got here without finding a single acyclic network.
# so try with a less dense network
return _randomize(density/2)
开发者ID:Anaphory,项目名称:pebl,代码行数:31,代码来源:network.py
示例3: degree_dist
def degree_dist(g):
if isinstance(g,np.ndarray):
g=nx.to_networkx_graph(g) # if matrix is passed, convert to networkx
d=dict(g.degree()).values()
vals=list(set(d))
counts=[d.count(i) for i in vals]
return list(zip(vals, counts))
开发者ID:AusterweilLab,项目名称:randomwalk,代码行数:7,代码来源:netstats.py
示例4: t_delta_partition
def t_delta_partition(t_delta_matrix,sm,verbose=False):
import community;
g=nx.to_networkx_graph(t_delta_matrix+t_delta_matrix.T - np.diag(t_delta_matrix.diagonal()) ,create_using=nx.Graph());
if verbose==True:
plt.figure, plt.pcolor(np.array(nx.to_numpy_matrix(g))), plt.colorbar();
plt.show()
return community.best_partition(g);
开发者ID:lordgrilo,项目名称:TemporalStability,代码行数:7,代码来源:TemporalStability.py
示例5: test_exceptions
def test_exceptions(self):
# _prep_create_using
G = {"a": "a"}
H = nx.to_networkx_graph(G)
assert_graphs_equal(H, nx.Graph([('a', 'a')]))
assert_raises(TypeError, to_networkx_graph, G, create_using=0.0)
# NX graph
class G(object):
adj = None
assert_raises(nx.NetworkXError, to_networkx_graph, G)
# pygraphviz agraph
class G(object):
is_strict = None
assert_raises(nx.NetworkXError, to_networkx_graph, G)
# Dict of [dicts, lists]
G = {"a": 0}
assert_raises(TypeError, to_networkx_graph, G)
# list or generator of edges
class G(object):
next = None
assert_raises(nx.NetworkXError, to_networkx_graph, G)
# no match
assert_raises(nx.NetworkXError, to_networkx_graph, "a")
开发者ID:ProgVal,项目名称:networkx,代码行数:31,代码来源:test_convert.py
示例6: identity_conversion
def identity_conversion(self, G, A, create_using):
GG = nx.from_numpy_matrix(A, create_using=create_using)
self.assert_equal(G, GG)
GW = nx.to_networkx_graph(A, create_using=create_using)
self.assert_equal(G, GW)
GI = create_using.__class__(A)
self.assert_equal(G, GI)
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:7,代码来源:test_convert_numpy.py
示例7: identity_conversion
def identity_conversion(self, G, A, create_using):
GG = nx.from_scipy_sparse_matrix(A, create_using=create_using)
self.assert_equal(G, GG)
GW = nx.to_networkx_graph(A, create_using=create_using)
self.assert_equal(G, GW)
GI = create_using.__class__(A)
self.assert_equal(G, GI)
ACSR = A.tocsr()
GI = create_using.__class__(ACSR)
self.assert_equal(G, GI)
ACOO = A.tocoo()
GI = create_using.__class__(ACOO)
self.assert_equal(G, GI)
ACSC = A.tocsc()
GI = create_using.__class__(ACSC)
self.assert_equal(G, GI)
AD = A.todense()
GI = create_using.__class__(AD)
self.assert_equal(G, GI)
AA = A.toarray()
GI = create_using.__class__(AA)
self.assert_equal(G, GI)
开发者ID:argriffing,项目名称:networkx,代码行数:29,代码来源:test_convert_scipy.py
示例8: geoGraph
def geoGraph(n, d, epsilon):
""" Create a geometric graph: n points in d-dimensional space,
nodes are connected if closer than epsilon"""
points = np.random.random((n,d))
pl2 = np.array([np.linalg.norm(points, axis=1)])**2
eucDist = (pl2.T @ np.ones((1,n))) + (np.ones((n,1)) @ pl2) - (2 * points @ points.T)
A = ((eucDist + np.eye(n)) < epsilon).astype(int)
return nx.to_networkx_graph(A)
开发者ID:EdwardBetts,项目名称:matching-metrics,代码行数:8,代码来源:graphGen.py
示例9: identity_conversion
def identity_conversion(self, G, A, create_using):
assert(A.sum() > 0)
GG = nx.from_numpy_array(A, create_using=create_using)
self.assert_equal(G, GG)
GW = nx.to_networkx_graph(A, create_using=create_using)
self.assert_equal(G, GW)
GI = nx.empty_graph(0, create_using).__class__(A)
self.assert_equal(G, GI)
开发者ID:jianantian,项目名称:networkx,代码行数:8,代码来源:test_convert_numpy.py
示例10: StickyGraph
def StickyGraph(n, deg):
"""input: n, degree sequence."""
assert(n == len(deg))
deg = np.array(deg) / np.sqrt(np.sum(deg))
A = np.zeros((n,n),dtype=int)
for i,j in itertools.combinations(range(n),2):
if (i != j) and (np.random.random() < deg[i]*deg[j]):
A[i,j] = 1
A[j,i] = 1
return nx.to_networkx_graph(A)
开发者ID:EdwardBetts,项目名称:matching-metrics,代码行数:10,代码来源:graphGen.py
示例11: geoGraphP
def geoGraphP(n, d, p):
""" Create a geometric graph: n points in d-dimensional space,
fraction p node pairs are connected"""
points = np.random.random((n,d))
pl2 = np.array([np.linalg.norm(points, axis=1)])**2
eucDist = (pl2.T @ np.ones((1,n))) + (np.ones((n,1)) @ pl2) - (2 * points @ points.T)
dists = np.sort(np.ravel(eucDist))
epsilon = dists[n + np.floor((n**2-n) * p).astype(int)]
A = ((eucDist + dists[-1] * np.eye(n)) < epsilon).astype(int)
return nx.to_networkx_graph(A)
开发者ID:EdwardBetts,项目名称:matching-metrics,代码行数:10,代码来源:graphGen.py
示例12: hits_algo
def hits_algo(adj_matrix,hub_score):
# INPUT: Initial hub_score, authorities score and adjacency matrix.
# OUTPUT: Converged
print "Running HITS algorithm..."
graph = nx.to_networkx_graph(adj_matrix)
# print graph
nstart = dict([(i, hub_score[i]) for i in xrange(len(hub_score))])
# print nstart
# return nx.hits(graph)
return nx.hits(graph,nstart=nstart)
开发者ID:moontails,项目名称:PROM,代码行数:10,代码来源:hits.py
示例13: convertIDToGraph
def convertIDToGraph(id,motifSize):
binary = bin(id);
adj = np.zeros(motifSize*motifSize)
for x in xrange(motifSize*motifSize):
if binary[-x] == 'b':
break
adj[-x] = int(binary[-x])
adj.shape = (motifSize,motifSize)
graph = nx.to_networkx_graph(adj,create_using=nx.DiGraph())
nx.draw_circular(graph)
#plt.savefig("result/id-"+str(id)+"size-"+str(motifSize))
plt.show()
开发者ID:Jason3424,项目名称:Network-Motif,代码行数:12,代码来源:GraphParse_fanmod.py
示例14: __init__
def __init__(self, term_term_matrix, threshold=10):
self.graph = {}
for term_a in term_term_matrix:
for term_b in term_term_matrix:
if term_term_matrix[term_a][term_b] >= threshold:
tmp = self.graph.get(term_a, [])
tmp.append(term_b)
self.graph[term_a] = tmp
if term_a not in self.graph:
self.graph[term_a] = []
self.nx_graph = nx.to_networkx_graph(self.graph)
开发者ID:Neymello,项目名称:clusterator,代码行数:14,代码来源:graph.py
示例15: test_graph_generator
def test_graph_generator():
A1 = np.loadtxt("adj_allVillageRelationships_vilno_1.csv", delimiter=",")
A2 = np.loadtxt("adj_allVillageRelationships_vilno_2.csv", delimiter=",")
G1 = nx.to_networkx_graph(A1)
G2 = nx.to_networkx_graph(A2)
gen1 = nx.connected_component_subgraphs(G1)
G1_LCC = max(gen1, key=len)
print(len(G1_LCC))
print(G1.number_of_nodes())
print(G1_LCC.number_of_nodes())
print(G1_LCC.number_of_nodes()/G1.number_of_nodes())
# g1 = gen1.__next__()
# print(g1)
# basic_net_stats(G1)
# basic_net_stats(g1)
gen2 = nx.connected_component_subgraphs(G2)
G2_LCC = max(gen2, key=len)
print(len(G2_LCC))
print(G2.number_of_nodes())
print(G2_LCC.number_of_nodes())
print(G2_LCC.number_of_nodes()/G2.number_of_nodes())
plt.figure()
nx.draw(G2_LCC, with_labels=False)
plt.show()
开发者ID:piotrbla,项目名称:pyExamples,代码行数:24,代码来源:bird_tracking.py
示例16: convert_matrix_to_digraph
def convert_matrix_to_digraph(matrix):
"""
Converts a python's matrix into a networkx's digraph.
Args:
matrix : MATRIX[[INT, INT, ...], [INT, INT, ...], ...]
This matrix is the representation of the genes
Returns:
nx.DiGraph()
The converted matrix into a digraph
"""
genes = np.asmatrix(matrix)
di_graph = nx.to_networkx_graph(genes, create_using=nx.DiGraph())
return di_graph
开发者ID:davidjjohn,项目名称:SGA_Project,代码行数:15,代码来源:general_functions.py
示例17: drawG
def drawG(g,Xs=[],labels={},save=False,display=True):
if type(g) == np.ndarray:
g=nx.to_networkx_graph(g)
nx.relabel_nodes(g, labels, copy=False)
#pos=nx.spring_layout(g, scale=5.0)
pos = nx.graphviz_layout(g, prog="fdp")
nx.draw_networkx(g,pos,node_size=1000)
# for node in range(numnodes): # if the above doesn't work
# plt.annotate(str(node), xy=pos[node]) # here's a workaround
if Xs != []:
plt.title(Xs)
plt.axis('off')
if save==True:
plt.savefig('temp.png') # need to parameterize
if display==True:
plt.show()
开发者ID:FilipMiscevic,项目名称:randomwalk,代码行数:16,代码来源:rw.py
示例18: convertIDToGraph
def convertIDToGraph(id,motifSize,save=False):
"""Plot graph with id and motifSize"""
binary = bin(id);
adj = np.zeros(motifSize*motifSize)
for x in xrange(motifSize*motifSize):
x+=1
if binary[-x] == 'b':
break
adj[-x] = int(binary[-x])
adj.shape = (motifSize,motifSize)
graph = nx.to_networkx_graph(adj,create_using=nx.DiGraph())
nx.draw_circular(graph)
if save:
plt.savefig("result/id-"+str(id)+"size-"+str(motifSize))
else:
plt.show()
plt.clf()
开发者ID:Jason3424,项目名称:Network-Motif,代码行数:17,代码来源:GraphParse.py
示例19: test_from_edgelist
def test_from_edgelist(self):
# Pandas DataFrame
g = nx.cycle_graph(10)
G = nx.Graph()
G.add_nodes_from(g)
G.add_weighted_edges_from((u, v, u) for u, v in g.edges())
edgelist = nx.to_edgelist(G)
source = [s for s, t, d in edgelist]
target = [t for s, t, d in edgelist]
weight = [d['weight'] for s, t, d in edgelist]
edges = pd.DataFrame({'source': source,
'target': target,
'weight': weight})
GG = nx.from_pandas_edgelist(edges, edge_attr='weight')
assert_nodes_equal(G.nodes(), GG.nodes())
assert_edges_equal(G.edges(), GG.edges())
GW = nx.to_networkx_graph(edges, create_using=nx.Graph())
assert_nodes_equal(G.nodes(), GW.nodes())
assert_edges_equal(G.edges(), GW.edges())
开发者ID:ProgVal,项目名称:networkx,代码行数:19,代码来源:test_convert_pandas.py
示例20: convertIDToGraph
def convertIDToGraph(mid, motifSize, save=False):
"""Draw graph with id and motifSize"""
binary = bin(mid);
adj = np.zeros(motifSize*motifSize)
l = 0
for x in xrange(1,motifSize*motifSize+1):
if binary[-x+l] == 'b':
break
if (x-1) % (motifSize+1) == 0:
l += 1
else:
adj[-x] = int(binary[-x+l])
adj.shape = (motifSize,motifSize)
graph = nx.to_networkx_graph(adj,create_using=nx.DiGraph())
nx.draw_circular(graph)
if save:
plt.savefig("result/id-"+str(id)+"size-"+str(motifSize))
else:
plt.show()
plt.clf()
开发者ID:deltaalex,项目名称:Network-Motif,代码行数:20,代码来源:FinalMotif.py
注:本文中的networkx.to_networkx_graph函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论