Skip to content

Instantly share code, notes, and snippets.

@marquisthunder
Created April 16, 2018 05:59
Show Gist options
  • Select an option

  • Save marquisthunder/09aa45c38a4f2fad170baa0e5a2305f7 to your computer and use it in GitHub Desktop.

Select an option

Save marquisthunder/09aa45c38a4f2fad170baa0e5a2305f7 to your computer and use it in GitHub Desktop.
[graph_tool] rand_neightbor
import graph_tool
from graph_tool.spectral import adjacency
import numpy as np
g = graph_tool.Graph()
g.add_vertex(100)
edges = np.random.randint(0, 100, (500,2))
g.add_edge_list(edges)
mat = adjacency(g).tolil()
rows = mat.rows.copy() # mat.rows = in-neighbours for each vertex
map(np.random.shuffle, rows)
rnd_neighbours = { i:row[0] for i, row in enumerate(rows) if row }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment