Ask Your Question

Revision history [back]

How to find the sum weight on a vertex

Hi I want to define a random labeling on edges of a graph (without duplicate labels ) and then find the sum of the weights of incident edges to each vertex. Here is code I wrote:

import random
w_edges = [(E[i][0], E[i][1], W[i]) for i in xrange(q)]
for i in G.vertex_iterator():
     x=sum(W[k] for k in G.neighbor_iterator(i))

But I receive some errors. I'll be happy if you can help me.