You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi
I am searching for a quick way to do random walks and saw this package that claims to be good, but when comparing it with naive python approach, the naive approach was much faster... what am I missing?
importnetworkxasnximportnumpyasnpimportcsrgraphascgfromtimeimporttimeimportrandomwalk_len=20G=nx.fast_gnp_random_graph(100, 0.3, directed=True) # just a random graphGG=cg.csrgraph(G)
t1=time()
walks=GG.random_walks(walklen=walk_len)
t2=time()
walks=np.zeros((len(G.nodes()), walk_len))
fori, nodeinenumerate(G.nodes()):
cur_node=nodeforjinrange(walk_len):
neighbor=random.choice(list(G.neighbors(cur_node))) # choose one random neighborwalks[i][j] =neighbor# add it to walkcur_node=neighbor# save it to cur_node to continue from it next iterationt3=time()
print('cg ', t2-t1)
print('naive ', t3-t2)
Hi
I am searching for a quick way to do random walks and saw this package that claims to be good, but when comparing it with naive python approach, the naive approach was much faster... what am I missing?
output:
cg 5.419240713119507
naive 0.010957479476928711
The text was updated successfully, but these errors were encountered: