2
"""Generators of x-y pairs of node data."""
4
from networkx.utils import dict_to_numpy_array
5
__author__ = ' '.join(['Aric Hagberg <aric.hagberg@gmail.com>'])
6
__all__ = ['node_attribute_xy',
9
def node_attribute_xy(G, attribute, nodes=None):
10
"""Return iterator of node-attribute pairs for all edges in G.
17
The node attribute key.
19
nodes: list or iterable (optional)
20
Use only edges that are adjacency to specified nodes.
21
The default is all nodes.
26
Generates 2-tuple of (attribute,attribute) values.
31
>>> G.add_node(1,color='red')
32
>>> G.add_node(2,color='blue')
34
>>> list(nx.node_attribute_xy(G,'color'))
39
For undirected graphs each edge is produced twice, once for each edge
40
representation (u,v) and (v,u), with the exception of self-loop edges
41
which only appear once.
48
for u,nbrsdict in G.adjacency_iter():
51
uattr = node[u].get(attribute,None)
53
for v,keys in nbrsdict.items():
54
vattr = node[v].get(attribute,None)
55
for k,d in keys.items():
58
for v,eattr in nbrsdict.items():
59
vattr = node[v].get(attribute,None)
63
def node_degree_xy(G, x='out', y='in', weight=None, nodes=None):
64
"""Generate node degree-degree pairs for edges in G.
70
x: string ('in','out')
71
The degree type for source node (directed graphs only).
73
y: string ('in','out')
74
The degree type for target node (directed graphs only).
76
weight: string or None, optional (default=None)
77
The edge attribute that holds the numerical value used
78
as a weight. If None, then each edge has weight 1.
79
The degree is the sum of the edge weights adjacent to the node.
81
nodes: list or iterable (optional)
82
Use only edges that are adjacency to specified nodes.
83
The default is all nodes.
88
Generates 2-tuple of (degree,degree) values.
95
>>> list(nx.node_degree_xy(G,x='out',y='in'))
97
>>> list(nx.node_degree_xy(G,x='in',y='out'))
102
For undirected graphs each edge is produced twice, once for each edge
103
representation (u,v) and (v,u), with the exception of self-loop edges
104
which only appear once.
113
direction = {'out':G.out_degree_iter,
114
'in':G.in_degree_iter}
118
for u,degu in xdeg(nodes, weight=weight):
119
neighbors = (nbr for _,nbr in G.edges_iter(u) if nbr in nodes)
120
for v,degv in ydeg(neighbors, weight=weight):
124
# fixture for nose tests
125
def setup_module(module):
126
from nose import SkipTest
130
raise SkipTest("NumPy not available")
134
raise SkipTest("SciPy not available")