Skip to content

Instantly share code, notes, and snippets.

@bmtgoncalves
Created October 4, 2016 08:07
Show Gist options
  • Save bmtgoncalves/0919d8c1b57ee0f477d6b906f3b15212 to your computer and use it in GitHub Desktop.
Save bmtgoncalves/0919d8c1b57ee0f477d6b906f3b15212 to your computer and use it in GitHub Desktop.
def BarabasiAlbert(N):
net = np.zeros(2*N, dtype='int')
# Edges represented by sequence of nodes
net[:6] = [0, 1, 1, 2, 2, 3]
# Generate the network
for i in xrange(3, N):
pos = np.random.randint(0, i)
net[2*i] = i
net[2*i+1] = net[pos]
return net
@paracycle
Copy link

Shouldn't Line 11 be

net[2*i+1] = net[2*pos]

?
Otherwise, you are limiting the range of 2*i+1 (edge) values to only the first half of the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment