当前位置: 首页>>代码示例>>Python>>正文


Python networkx.number_of_edges方法代码示例

本文整理汇总了Python中networkx.number_of_edges方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.number_of_edges方法的具体用法?Python networkx.number_of_edges怎么用?Python networkx.number_of_edges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.number_of_edges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_iterators

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_iterators(self):
        G=self.G()
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), 
                          ('C', 'B'), ('C', 'D')])
        G.add_nodes_from('GJK')
        assert_equal(sorted(G.nodes_iter()),
                     ['A', 'B', 'C', 'D', 'G', 'J', 'K'])
        assert_edges_equal(G.edges_iter(),
        [('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')])

        assert_equal(sorted([v for k,v in G.degree_iter()]),
                     [0, 0, 0, 2, 2, 3, 3])
        assert_equal(sorted(G.degree_iter(),key=str),
                     [('A', 2), ('B', 3), ('C', 3), ('D', 2), 
                      ('G', 0), ('J', 0), ('K', 0)])
        assert_equal(sorted(G.neighbors_iter('A')),['B', 'C'])
        assert_raises(nx.NetworkXError,G.neighbors_iter,'X')
        G.clear()
        assert_equal(nx.number_of_nodes(G),0)
        assert_equal(nx.number_of_edges(G),0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:22,代码来源:historical_tests.py

示例2: test_iterators

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_iterators(self):
        G = self.G()
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),
                          ('C', 'B'), ('C', 'D')])
        G.add_nodes_from('GJK')
        assert_equal(sorted(G.nodes()),
                     ['A', 'B', 'C', 'D', 'G', 'J', 'K'])
        assert_edges_equal(G.edges(),
                           [('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')])

        assert_equal(sorted([v for k, v in G.degree()]),
                     [0, 0, 0, 2, 2, 3, 3])
        assert_equal(sorted(G.degree(), key=str),
                     [('A', 2), ('B', 3), ('C', 3), ('D', 2),
                      ('G', 0), ('J', 0), ('K', 0)])
        assert_equal(sorted(G.neighbors('A')), ['B', 'C'])
        assert_raises(nx.NetworkXError, G.neighbors, 'X')
        G.clear()
        assert_equal(nx.number_of_nodes(G), 0)
        assert_equal(nx.number_of_edges(G), 0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:historical_tests.py

示例3: test_nondecreasing_degree_sequence

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_nondecreasing_degree_sequence(self):
        # Check for lexicographically nondecreasing degree sequences
        # (for fixed number of nodes and edges).
        #
        # There are three exceptions to this rule in the order given in
        # the "Atlas of Graphs" book, so we need to manually exclude
        # those.
        exceptions = [('G55', 'G56'), ('G1007', 'G1008'), ('G1012', 'G1013')]
        for n, group in groupby(self.GAG, key=nx.number_of_nodes):
            for m, group in groupby(group, key=nx.number_of_edges):
                for G1, G2 in pairwise(group):
                    if (G1.name, G2.name) in exceptions:
                        continue
                    d1 = sorted(d for v, d in G1.degree())
                    d2 = sorted(d for v, d in G2.degree())
                    assert_less_equal(d1, d2) 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_atlas.py

示例4: test_size

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_size(self):
        num_nodes = nx.number_of_nodes(self.graph)
        self.assertEqual(num_nodes, 3971, "Should be 3971.")
        num_edges = nx.number_of_edges(self.graph)
        self.assertEqual(num_edges, 28202, "Should be 28202.") 
开发者ID:baryshnikova-lab,项目名称:safepy,代码行数:7,代码来源:test_imports.py

示例5: __weight

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def __weight(community):
    """

    :param community: a subgraph/algorithms in the graph
    :return: weight of the algorithms (using the formula mentioned in the paper)
    """
    if nx.number_of_nodes(community) == 0:
        return 0
    else:
        return float(2 * nx.number_of_edges(community) / nx.number_of_nodes(community)) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:12,代码来源:LAIS2_nx.py

示例6: test_order_size

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_order_size(self):
        G=self.G()
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), 
                          ('C', 'B'), ('C', 'D')])
        assert_equal(G.order(),4)
        assert_equal(G.size(),5)
        assert_equal(G.number_of_edges(),5)
        assert_equal(G.number_of_edges('A','B'),1)
        assert_equal(G.number_of_edges('A','D'),0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:historical_tests.py

示例7: test_number_of_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_number_of_edges(self):
        assert_equal(self.G.number_of_edges(),nx.number_of_edges(self.G))
        assert_equal(self.DG.number_of_edges(),nx.number_of_edges(self.DG)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_function.py

示例8: test_create_graph_state

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_create_graph_state():
    graph = nx.complete_graph(4)
    graph = nx.relabel_nodes(graph, {i: i * 2 for i in range(4)})
    prog = create_graph_state(graph)
    n_czs = 0
    for line in prog.out().splitlines():
        if line.startswith('CZ'):
            n_czs += 1

    assert n_czs == nx.number_of_edges(graph) 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:12,代码来源:test_entangled_states.py

示例9: test_order_size

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_order_size(self):
        G = self.G()
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'),
                          ('C', 'B'), ('C', 'D')])
        assert_equal(G.order(), 4)
        assert_equal(G.size(), 5)
        assert_equal(G.number_of_edges(), 5)
        assert_equal(G.number_of_edges('A', 'B'), 1)
        assert_equal(G.number_of_edges('A', 'D'), 0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:11,代码来源:historical_tests.py

示例10: test_number_of_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_number_of_edges(self):
        assert_equal(self.G.number_of_edges(), nx.number_of_edges(self.G))
        assert_equal(self.DG.number_of_edges(), nx.number_of_edges(self.DG)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_function.py

示例11: test_sizes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_sizes(self):
        G = self.GAG[0]
        assert_equal(G.number_of_nodes(), 0)
        assert_equal(G.number_of_edges(), 0)

        G = self.GAG[7]
        assert_equal(G.number_of_nodes(), 3)
        assert_equal(G.number_of_edges(), 3) 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_atlas.py

示例12: test_nondecreasing_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_nondecreasing_edges(self):
        # check for nondecreasing number of edges (for fixed number of
        # nodes)
        for n, group in groupby(self.GAG, key=nx.number_of_nodes):
            for m1, m2 in pairwise(map(nx.number_of_edges, group)):
                assert_less_equal(m2, m1 + 1) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_atlas.py

示例13: density

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def density(B, nodes):
    """Return density of bipartite graph B.

    Parameters
    ----------
    G : NetworkX graph

    nodes: list or container
      Nodes in one set of the bipartite graph.

    Returns
    -------
    d : float
       The bipartite density

    Examples
    --------
    >>> from networkx.algorithms import bipartite
    >>> G = nx.complete_bipartite_graph(3,2)
    >>> X=set([0,1,2])
    >>> bipartite.density(G,X)
    1.0
    >>> Y=set([3,4])
    >>> bipartite.density(G,Y)
    1.0

    See Also
    --------
    color
    """
    n=len(B)
    m=nx.number_of_edges(B)
    nb=len(nodes)
    nt=n-nb
    if m==0: # includes cases n==0 and n==1
        d=0.0
    else:
        if B.is_directed():
            d=m/(2.0*float(nb*nt))
        else:
            d= m/float(nb*nt)
    return d 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:44,代码来源:basic.py

示例14: test_union_all_and_compose_all

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def test_union_all_and_compose_all():
    K3=nx.complete_graph(3)
    P3=nx.path_graph(3)

    G1=nx.DiGraph()
    G1.add_edge('A','B')
    G1.add_edge('A','C')
    G1.add_edge('A','D')
    G2=nx.DiGraph()
    G2.add_edge('1','2')
    G2.add_edge('1','3')
    G2.add_edge('1','4')

    G=nx.union_all([G1,G2])
    H=nx.compose_all([G1,G2])
    assert_edges_equal(G.edges(),H.edges())
    assert_false(G.has_edge('A','1'))
    assert_raises(nx.NetworkXError, nx.union, K3, P3)
    H1=nx.union_all([H,G1],rename=('H','G1'))
    assert_equal(sorted(H1.nodes()),
        ['G1A', 'G1B', 'G1C', 'G1D',
         'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD'])

    H2=nx.union_all([H,G2],rename=("H",""))
    assert_equal(sorted(H2.nodes()),
        ['1', '2', '3', '4',
         'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD'])

    assert_false(H1.has_edge('NB','NA'))

    G=nx.compose_all([G,G])
    assert_edges_equal(G.edges(),H.edges())

    G2=nx.union_all([G2,G2],rename=('','copy'))
    assert_equal(sorted(G2.nodes()),
        ['1', '2', '3', '4', 'copy1', 'copy2', 'copy3', 'copy4'])

    assert_equal(G2.neighbors('copy4'),[])
    assert_equal(sorted(G2.neighbors('copy1')),['copy2', 'copy3', 'copy4'])
    assert_equal(len(G),8)
    assert_equal(nx.number_of_edges(G),6)

    E=nx.disjoint_union_all([G,G])
    assert_equal(len(E),16)
    assert_equal(nx.number_of_edges(E),12)

    E=nx.disjoint_union_all([G1,G2])
    assert_equal(sorted(E.nodes()),[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])

    G1=nx.DiGraph()
    G1.add_edge('A','B')
    G2=nx.DiGraph()
    G2.add_edge(1,2)
    G3=nx.DiGraph()
    G3.add_edge(11,22)
    G4=nx.union_all([G1,G2,G3],rename=("G1","G2","G3"))
    assert_equal(sorted(G4.nodes()),
        ['G1A', 'G1B', 'G21', 'G22',
         'G311', 'G322']) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:61,代码来源:test_all.py

示例15: density

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import number_of_edges [as 别名]
def density(B, nodes):
    """Returns density of bipartite graph B.

    Parameters
    ----------
    G : NetworkX graph

    nodes: list or container
      Nodes in one node set of the bipartite graph.

    Returns
    -------
    d : float
       The bipartite density

    Examples
    --------
    >>> from networkx.algorithms import bipartite
    >>> G = nx.complete_bipartite_graph(3,2)
    >>> X=set([0,1,2])
    >>> bipartite.density(G,X)
    1.0
    >>> Y=set([3,4])
    >>> bipartite.density(G,Y)
    1.0

    Notes
    -----
    The container of nodes passed as argument must contain all nodes
    in one of the two bipartite node sets to avoid ambiguity in the
    case of disconnected graphs.
    See :mod:`bipartite documentation <networkx.algorithms.bipartite>`
    for further details on how bipartite graphs are handled in NetworkX.

    See Also
    --------
    color
    """
    n = len(B)
    m = nx.number_of_edges(B)
    nb = len(nodes)
    nt = n - nb
    if m == 0:  # includes cases n==0 and n==1
        d = 0.0
    else:
        if B.is_directed():
            d = m / (2.0 * float(nb * nt))
        else:
            d = m / float(nb * nt)
    return d 
开发者ID:holzschu,项目名称:Carnets,代码行数:52,代码来源:basic.py


注:本文中的networkx.number_of_edges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。