當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。