Skip to content

Commit d7ce1d4

Browse files
committed
use numpy arrays in the example
1 parent b03d67e commit d7ce1d4

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

examples/static_network_percolation/static_network_percolation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def cc_analysis(n: int, p: float, seed: int):
1212
# The Reticula magic is happening in this paragraph:
1313
state = ret.mersenne_twister(seed)
1414
g = ret.random_gnp_graph[ret.int64](n, p, state)
15-
ccs = [len(cc) for cc in ret.connected_components(g)]
15+
ccs = np.array([len(cc) for cc in ret.connected_components(g)])
1616

17-
largest_comp_size = max(ccs)
18-
sum_squares = sum([s**2 for s in ccs])
19-
sum_cubes = sum([s**3 for s in ccs])
17+
largest_comp_size = np.max(ccs)
18+
sum_squares = np.sum(ccs**2)
19+
sum_cubes = np.sum(ccs**3)
2020
nom = sum_squares - largest_comp_size**2
2121
denom = n - largest_comp_size
2222
classic_chi = nom/denom if denom > 0 else 0.0

0 commit comments

Comments
 (0)