Fixed database typo and removed unnecessary class identifier.
This commit is contained in:
parent
00ad49a143
commit
45fb349a7d
5098 changed files with 952558 additions and 85 deletions
2
venv/share/doc/networkx-2.5/examples/basic/README.txt
Normal file
2
venv/share/doc/networkx-2.5/examples/basic/README.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
Basic
|
||||
-----
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,48 @@
|
|||
"""
|
||||
==========
|
||||
Properties
|
||||
==========
|
||||
|
||||
Compute some network properties for the lollipop graph.
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
from networkx import nx
|
||||
|
||||
G = nx.lollipop_graph(4, 6)
|
||||
|
||||
pathlengths = []
|
||||
|
||||
print("source vertex {target:length, }")
|
||||
for v in G.nodes():
|
||||
spl = dict(nx.single_source_shortest_path_length(G, v))
|
||||
print(f"{v} {spl} ")
|
||||
for p in spl:
|
||||
pathlengths.append(spl[p])
|
||||
|
||||
print()
|
||||
print(f"average shortest path length {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(f"{d} {dist[d]}")
|
||||
|
||||
print(f"radius: {nx.radius(G)}")
|
||||
print(f"diameter: {nx.diameter(G)}")
|
||||
print(f"eccentricity: {nx.eccentricity(G)}")
|
||||
print(f"center: {nx.center(G)}")
|
||||
print(f"periphery: {nx.periphery(G)}")
|
||||
print(f"density: {nx.density(G)}")
|
||||
|
||||
nx.draw(G, with_labels=True)
|
||||
plt.show()
|
|
@ -0,0 +1,23 @@
|
|||
"""
|
||||
======================
|
||||
Read and write graphs.
|
||||
======================
|
||||
|
||||
Read and write graphs.
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import networkx as nx
|
||||
|
||||
G = nx.grid_2d_graph(5, 5) # 5x5 grid
|
||||
|
||||
# print the adjacency list
|
||||
for line in nx.generate_adjlist(G):
|
||||
print(line)
|
||||
# write edgelist to grid.edgelist
|
||||
nx.write_edgelist(G, path="grid.edgelist", delimiter=":")
|
||||
# read edgelist from grid.edgelist
|
||||
H = nx.read_edgelist(path="grid.edgelist", delimiter=":")
|
||||
|
||||
nx.draw(H)
|
||||
plt.show()
|
Loading…
Add table
Add a link
Reference in a new issue