本文整理汇总了Python中networkx.generators.classic.path_graph函数的典型用法代码示例。如果您正苦于以下问题:Python path_graph函数的具体用法?Python path_graph怎么用?Python path_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了path_graph函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_nodelist
def test_nodelist(self):
"""Conversion from graph to matrix to graph with nodelist."""
P4 = path_graph(4)
P3 = path_graph(3)
nodelist = P3.nodes()
A = nx.to_numpy_matrix(P4, nodelist=nodelist)
GA = nx.Graph(A)
self.assert_equal(GA, P3)
# Make nodelist ambiguous by containing duplicates.
nodelist += [nodelist[0]]
assert_raises(nx.NetworkXError, nx.to_numpy_matrix, P3, nodelist=nodelist)
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:12,代码来源:test_convert_numpy.py
示例2: test_format_keyword
def test_format_keyword(self):
WP4 = nx.Graph()
WP4.add_edges_from( (n,n+1,dict(weight=0.5,other=0.3))
for n in range(3) )
P4 = path_graph(4)
A = nx.to_scipy_sparse_matrix(P4, format='csr')
np_assert_equal(A.todense(),
nx.to_scipy_sparse_matrix(WP4,weight=None).todense())
A = nx.to_scipy_sparse_matrix(P4, format='csc')
np_assert_equal(A.todense(),
nx.to_scipy_sparse_matrix(WP4,weight=None).todense())
A = nx.to_scipy_sparse_matrix(P4, format='coo')
np_assert_equal(A.todense(),
nx.to_scipy_sparse_matrix(WP4,weight=None).todense())
A = nx.to_scipy_sparse_matrix(P4, format='bsr')
np_assert_equal(A.todense(),
nx.to_scipy_sparse_matrix(WP4,weight=None).todense())
A = nx.to_scipy_sparse_matrix(P4, format='lil')
np_assert_equal(A.todense(),
nx.to_scipy_sparse_matrix(WP4,weight=None).todense())
A = nx.to_scipy_sparse_matrix(P4, format='dia')
np_assert_equal(A.todense(),
nx.to_scipy_sparse_matrix(WP4,weight=None).todense())
A = nx.to_scipy_sparse_matrix(P4, format='dok')
np_assert_equal(A.todense(),
nx.to_scipy_sparse_matrix(WP4,weight=None).todense())
开发者ID:argriffing,项目名称:networkx,代码行数:32,代码来源:test_convert_scipy.py
示例3: truncated_tetrahedron_graph
def truncated_tetrahedron_graph(create_using=None):
"""Return the skeleton of the truncated Platonic tetrahedron."""
G = path_graph(12, create_using)
# G.add_edges_from([(1,3),(1,10),(2,7),(4,12),(5,12),(6,8),(9,11)])
G.add_edges_from([(0, 2), (0, 9), (1, 6), (3, 11), (4, 11), (5, 7), (8, 10)])
G.name = "Truncated Tetrahedron Graph"
return G
开发者ID:JaneliaSciComp,项目名称:Neuroptikon,代码行数:7,代码来源:small.py
示例4: random_lobster
def random_lobster(n, p1, p2, seed=None):
"""Returns a random lobster graph.
A lobster is a tree that reduces to a caterpillar when pruning all
leaf nodes. A caterpillar is a tree that reduces to a path graph
when pruning all leaf nodes; setting ``p2`` to zero produces a caterillar.
Parameters
----------
n : int
The expected number of nodes in the backbone
p1 : float
Probability of adding an edge to the backbone
p2 : float
Probability of adding an edge one level beyond backbone
seed : int, optional
Seed for random number generator (default=None).
"""
# a necessary ingredient in any self-respecting graph library
if seed is not None:
random.seed(seed)
llen=int(2*random.random()*n + 0.5)
L=path_graph(llen)
L.name="random_lobster(%d,%s,%s)"%(n,p1,p2)
# build caterpillar: add edges to path graph with probability p1
current_node=llen-1
for n in range(llen):
if random.random()<p1: # add fuzzy caterpillar parts
current_node+=1
L.add_edge(n,current_node)
if random.random()<p2: # add crunchy lobster bits
current_node+=1
L.add_edge(current_node-1,current_node)
return L # voila, un lobster!
开发者ID:CaptainAL,项目名称:Spyder,代码行数:34,代码来源:random_graphs.py
示例5: random_lobster
def random_lobster(n, p1, p2, seed=None):
"""Return a random lobster.
A caterpillar is a tree that reduces to a path graph when pruning
all leaf nodes (p2=0).
A lobster is a tree that reduces to a caterpillar when pruning all
leaf nodes.
:Parameters:
- `n`: the expected number of nodes in the backbone
- `p1`: probability of adding an edge to the backbone
- `p2`: probability of adding an edge one level beyond backbone
- `seed`: seed for random number generator (default=None)
"""
# a necessary ingredient in any self-respecting graph library
if seed is not None:
random.seed(seed)
llen=int(2*random.random()*n + 0.5)
L=path_graph(llen)
L.name="random_lobster(%d,%s,%s)"%(n,p1,p2)
# build caterpillar: add edges to path graph with probability p1
current_node=llen-1
for n in xrange(llen):
if random.random()<p1: # add fuzzy caterpillar parts
current_node+=1
L.add_edge(n,current_node)
if random.random()<p2: # add crunchy lobster bits
current_node+=1
L.add_edge(current_node-1,current_node)
return L # voila, un lobster!
开发者ID:jbjorne,项目名称:CVSTransferTest,代码行数:31,代码来源:random_graphs.py
示例6: test_weight_keyword
def test_weight_keyword(self):
WP4 = nx.Graph()
WP4.add_edges_from( (n,n+1,dict(weight=0.5,other=0.3)) for n in range(3) )
P4 = path_graph(4)
A = nx.to_numpy_matrix(P4)
np_assert_equal(A, nx.to_numpy_matrix(WP4,weight=None))
np_assert_equal(0.5*A, nx.to_numpy_matrix(WP4))
np_assert_equal(0.3*A, nx.to_numpy_matrix(WP4,weight='other'))
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:8,代码来源:test_convert_numpy.py
示例7: test_weight_keyword
def test_weight_keyword(self):
WP4 = nx.Graph()
WP4.add_edges_from((n, n + 1, dict(weight=0.5, other=0.3)) for n in range(3))
P4 = path_graph(4)
A = nx.to_scipy_sparse_matrix(P4)
np_assert_equal(A.todense(), nx.to_scipy_sparse_matrix(WP4, weight=None).todense())
np_assert_equal(0.5 * A.todense(), nx.to_scipy_sparse_matrix(WP4).todense())
np_assert_equal(0.3 * A.todense(), nx.to_scipy_sparse_matrix(WP4, weight="other").todense())
开发者ID:GccX11,项目名称:networkx,代码行数:8,代码来源:test_convert_scipy.py
示例8: random_lobster
def random_lobster(n, p1, p2, create_using=None, seed=None):
"""Return a random lobster.
A lobster is a tree that reduces to a caterpillar when pruning all
leaf nodes.
A caterpillar is a tree that reduces to a path graph when pruning
all leaf nodes (p2=0).
Parameters
----------
n : int
The expected number of nodes in the backbone
p1 : float
Probability of adding an edge to the backbone
p2 : float
Probability of adding an edge one level beyond backbone
create_using : graph, optional (default Graph)
The graph instance used to build the graph.
seed : int, optional
Seed for random number generator (default=None).
"""
# a necessary ingredient in any self-respecting graph library
if seed is not None:
random.seed(seed)
llen=int(2*random.random()*n + 0.5)
if create_using is not None and create_using.is_directed():
raise nx.NetworkXError("Directed Graph not supported")
L=path_graph(llen,create_using)
L.name="random_lobster(%d,%s,%s)"%(n,p1,p2)
# build caterpillar: add edges to path graph with probability p1
current_node=llen-1
for n in xrange(llen):
if random.random()<p1: # add fuzzy caterpillar parts
current_node+=1
L.add_edge(n,current_node)
if random.random()<p2: # add crunchy lobster bits
current_node+=1
L.add_edge(current_node-1,current_node)
return L # voila, un lobster!
开发者ID:mhawthorne,项目名称:antonym,代码行数:40,代码来源:random_graphs.py
示例9: test_format_keyword_fail
def test_format_keyword_fail(self):
WP4 = nx.Graph()
WP4.add_edges_from( (n,n+1,dict(weight=0.5,other=0.3))
for n in range(3) )
P4 = path_graph(4)
nx.to_scipy_sparse_matrix(P4, format='any_other')
开发者ID:argriffing,项目名称:networkx,代码行数:6,代码来源:test_convert_scipy.py
注:本文中的networkx.generators.classic.path_graph函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论