Skip to content

Commit bb19ba3

Browse files
committed
Remove numpy dependency
1 parent 83dc194 commit bb19ba3

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

6 Bytes
Loading

doc/source/tutorials/minimum_spanning_trees/minimum_spanning_trees.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ We start by generating a grid graph with random weights
1717
1818
import igraph as ig
1919
import matplotlib.pyplot as plt
20-
import numpy as np
20+
import random
2121
2222
# Generate grid graph with random weights
23-
np.random.seed(0)
23+
random.seed(0)
2424
2525
g = ig.Graph.Lattice([5, 5], circular=False)
26-
g.es["weight"] = np.random.randint(1, 20, g.ecount()).tolist()
26+
g.es["weight"] = [random.randint(1, 20) for _ in g.es]
2727
2828
We then call |spanning_tree|_, making sure to pass in the randomly generated weights.
2929

doc/source/tutorials/spanning_trees/assets/spanning_trees.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import igraph as ig
22
import matplotlib.pyplot as plt
3-
import numpy as np
3+
import random
44

55
g = ig.Graph.Lattice([6, 6], circular=False)
66

77
# Optional: Rearrange the vertex ids to get a more interesting spanning tree
88
layout = g.layout("grid")
99

10-
np.random.seed(0)
11-
permutation = np.random.permutation(36)
12-
g = g.permute_vertices(permutation.tolist())
10+
random.seed(0)
11+
permutation = list(range(g.vcount()))
12+
random.shuffle(permutation)
13+
g = g.permute_vertices(permutation)
1314

1415
new_layout = g.layout("grid")
1516
for i in range(36):
@@ -34,5 +35,3 @@
3435
edge_width=g.es["width"]
3536
)
3637
plt.show()
37-
38-
-64 Bytes
Loading

doc/source/tutorials/spanning_trees/spanning_trees.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ First we create a 6 by 6 lattice graph.
1717
1818
import igraph as ig
1919
import matplotlib.pyplot as plt
20-
import numpy as np
20+
import random
2121
2222
g = ig.Graph.Lattice([6, 6], circular=False)
2323
@@ -31,9 +31,10 @@ As an optional step, we randomly rearrange some of the vertex IDs with |permute_
3131
# Optional: Rearrange the vertex ids to get a more interesting spanning tree
3232
layout = g.layout("grid")
3333
34-
np.random.seed(0)
35-
permutation = np.random.permutation(36)
36-
g = g.permute_vertices(permutation.tolist())
34+
random.seed(0)
35+
permutation = list(range(g.vcount()))
36+
random.shuffle(permutation)
37+
g = g.permute_vertices(permutation)
3738
3839
# Calculate the new layout coordinates based on the permutation
3940
new_layout = g.layout("grid")

0 commit comments

Comments
 (0)