k_shell#
- k_shell(G, k=None, core_number=None)[source]#
Returns the k-shell of G.
The k-shell is the subgraph induced by nodes with core number k. That is, nodes in the k-core that are not in the (k+1)-core.
Deprecated since version 3.3:
k_shell
will not acceptMultiGraph
objects in version 3.5.- Parameters:
- GNetworkX graph
A graph or directed graph.
- kint, optional
The order of the shell. If not specified return the outer shell.
- core_numberdictionary, optional
Precomputed core numbers for the graph G.
- Returns:
- GNetworkX graph
The k-shell subgraph
- Raises:
- NetworkXNotImplemented
The k-shell is not implemented for multigraphs or graphs with self loops.
See also
Notes
This is similar to k_corona but in that case only neighbors in the k-core are considered.
For directed graphs the node degree is defined to be the in-degree + out-degree.
Graph, node, and edge attributes are copied to the subgraph.
References
[1]A model of Internet topology using k-shell decomposition Shai Carmi, Shlomo Havlin, Scott Kirkpatrick, Yuval Shavitt, and Eran Shir, PNAS July 3, 2007 vol. 104 no. 27 11150-11154 http://www.pnas.org/content/104/27/11150.full
Examples
>>> degrees = [0, 1, 2, 2, 2, 2, 3] >>> H = nx.havel_hakimi_graph(degrees) >>> H.degree DegreeView({0: 1, 1: 2, 2: 2, 3: 2, 4: 2, 5: 3, 6: 0}) >>> nx.k_shell(H, k=1).nodes NodeView((0, 4))