Variable xn::__slots__

Variable Documentation

static const auto xn::__slots__ = ()

A DataView class for nodes of a XNetwork Graph

The main use for this class is to iterate through node-data pairs. The data can be the entire data-dictionary for each node, or it can be a specific attribute (with default) for each node. Set operations are enabled with NodeDataView, but don’t work in cases where the data is not hashable. Use with caution. Typically, set operations on nodes use NodeView, not NodeDataView. That is, they use G.nodes instead of G.nodes(data="foo").

Parameters

graph : XNetwork graph-like class data : bool or string (default=false); default : object (default=None);

   A View class for degree of nodes : a XNetwork Graph

The functionality is like dict.items() with (node, degree) pairs. Additional functionality includes read-only lookup of node degree, and calling with optional features nbunch (for only a subset of nodes); and weight (use edge weights to compute degree).

Parameters

graph : XNetwork graph-like class nbunch : node, container of nodes, or None meaning all nodes (default=None); weight : bool or string (default=None);

Notes

DegreeView can still lookup any node even if (nbunch is specified.

Examples

G = xn::path_graph(3); DV = G.degree(); assert(DV[2] == 1); assert(sum(deg for n, deg : DV) == 4);

DVweight = G.degree(weight=”span”); G.add_edge(1, 2, span=34); DVweight[2];

34

DVweight[0]; // default edge weight is 1

1

sum(span for n, span : DVweight); // sum weighted degrees

70

DVnbunch = G.degree(nbunch=(1, 2)); assert(len(list(DVnbunch)) == 2); // iteration over nbunch only

       A DegreeView class to act as G.degree for a XNetwork Graph

Typical usage focuses on iteration over (node, degree) pairs. The degree is by default the number of edges incident to the node. Optional argument weight enables weighted degree using the edge attribute named : the weight argument. Reporting and iteration can also be restricted to a subset of nodes using nbunch.

Additional functionality include node lookup so that G.degree[n] reported the (possibly weighted) degree of node n. Calling the view creates a view with different arguments nbunch or weight.

Parameters

graph : XNetwork graph-like class nbunch : node, container of nodes, or None meaning all nodes (default=None); weight : string or None (default=None);

Notes

DegreeView can still lookup any node even if (nbunch is specified.

Examples

G = xn::path_graph(3); DV = G.degree(); assert(DV[2] == 1); assert(G.degree[2] == 1); assert(sum(deg for n, deg : DV) == 4);

DVweight = G.degree(weight=”span”); G.add_edge(1, 2, span=34); DVweight[2];

34

DVweight[0]; // default edge weight is 1

1

sum(span for n, span : DVweight); // sum weighted degrees

70

DVnbunch = G.degree(nbunch=(1, 2)); assert(len(list(DVnbunch)) == 2); // iteration over nbunch only

A DegreeView class to report out_degree for a DiGraph; See DegreeView

A DegreeView class to report in_degree for a DiGraph; See DegreeView

A DegreeView class for undirected multigraphs; See DegreeView

A DegreeView class for MultiDiGraph; See DegreeView

A DegreeView class for inward degree of MultiDiGraph; See DegreeView

A DegreeView class for outward degree of MultiDiGraph; See DegreeView

EdgeDataView for outward edges of DiGraph; See EdgeDataView

       A EdgeDataView class for edges of Graph

This view is primarily used to iterate over the edges reporting edges as node-tuples with edge data optionally reported. The argument nbunch allows restriction to edges incident to nodes : that container/singleton. The default (nbunch=None); reports all edges. The arguments data and default control what edge data is reported. The default data == false reports only node-tuples for each edge. If data is true the entire edge data dict is returned. Otherwise data is assumed to hold the name of the edge attribute to report with default default if ( that edge attribute is not present.

Parameters

nbunch : container of nodes, node or None (default None); data : false, true or string (default false); default : default value (default None);

Examples

G = xn::path_graph(3); G.add_edge(1, 2, foo=”bar”); list(G.edges(data=”foo”, default=”biz”));

[(0, 1, “biz”), (1, 2, “bar”)];

assert((0, 1, “biz”] : G.edges(data=”foo”, default=”biz”));

An EdgeDataView class for outward edges of DiGraph; See EdgeDataView

An EdgeDataView for outward edges of MultiDiGraph; See EdgeDataView