/usr/share/doc/python-networkx/examples/basic/properties.py is in python-networkx 1.8.1-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #!/usr/bin/env python
"""
Compute some network properties for the lollipop graph.
"""
# Copyright (C) 2004 by
# Aric Hagberg <hagberg@lanl.gov>
# Dan Schult <dschult@colgate.edu>
# Pieter Swart <swart@lanl.gov>
# All rights reserved.
# BSD license.
from networkx import *
G = lollipop_graph(4,6)
pathlengths=[]
print("source vertex {target:length, }")
for v in G.nodes():
spl=single_source_shortest_path_length(G,v)
print('%s %s' % (v,spl))
for p in spl.values():
pathlengths.append(p)
print('')
print("average shortest path length %s" % (sum(pathlengths)/len(pathlengths)))
# histogram of path lengths
dist={}
for p in pathlengths:
if p in dist:
dist[p]+=1
else:
dist[p]=1
print('')
print("length #paths")
verts=dist.keys()
for d in sorted(verts):
print('%s %d' % (d,dist[d]))
print("radius: %d" % radius(G))
print("diameter: %d" % diameter(G))
print("eccentricity: %s" % eccentricity(G))
print("center: %s" % center(G))
print("periphery: %s" % periphery(G))
print("density: %s" % density(G))
|