ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 10 Jan 2020 17:57:56 +0100How to find the sum weight on a vertexhttps://ask.sagemath.org/question/49473/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:
n=[]
import random
W=random.sample(G.num_edges(),G.num_edges())
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))
n.append(x)
But I receive some errors. I'll be happy if you can help me.
Thu, 09 Jan 2020 16:09:44 +0100https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/Comment by John Palmieri for <p>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:</p>
<pre><code>n=[]
import random
W=random.sample(G.num_edges(),G.num_edges())
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))
n.append(x)
</code></pre>
<p>But I receive some errors. I'll be happy if you can help me.</p>
https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49475#post-id-49475What is `q`? What sorts of errors do you get? What is a sample graph that we can work with?Thu, 09 Jan 2020 20:02:30 +0100https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49475#post-id-49475Comment by John Palmieri for <p>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:</p>
<pre><code>n=[]
import random
W=random.sample(G.num_edges(),G.num_edges())
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))
n.append(x)
</code></pre>
<p>But I receive some errors. I'll be happy if you can help me.</p>
https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49491#post-id-49491Also, `random.sample` takes a list as the first argument, and `G.num_edges()` is a number, not a list.Fri, 10 Jan 2020 17:57:56 +0100https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49491#post-id-49491Comment by Milad for <p>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:</p>
<pre><code>n=[]
import random
W=random.sample(G.num_edges(),G.num_edges())
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))
n.append(x)
</code></pre>
<p>But I receive some errors. I'll be happy if you can help me.</p>
https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49481#post-id-49481@John
q=G.num_edges()
I get these errors:
Traceback (most recent call last): n.append(x)
File "", line 1, in <module>
File "/private/var/folders/v7/j_ry66_d0s333h_720qz836c0000gn/T/tmpu6JFBi/___code___.py", line 7
for i in G.vertex_iterator():
^
IndentationError: unexpected indentThu, 09 Jan 2020 21:48:36 +0100https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49481#post-id-49481Comment by Milad for <p>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:</p>
<pre><code>n=[]
import random
W=random.sample(G.num_edges(),G.num_edges())
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))
n.append(x)
</code></pre>
<p>But I receive some errors. I'll be happy if you can help me.</p>
https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49482#post-id-49482I wanted to obtain an antimagic labeling.
A graph G is antimagic if there exists a bijective edge labeling from E(G) to {1,..., |E(G)|} such that the vertex sums are pairwise distinct.
If you have another code, I will appreciate if you tell me.Thu, 09 Jan 2020 21:55:08 +0100https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49482#post-id-49482Comment by John Palmieri for <p>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:</p>
<pre><code>n=[]
import random
W=random.sample(G.num_edges(),G.num_edges())
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))
n.append(x)
</code></pre>
<p>But I receive some errors. I'll be happy if you can help me.</p>
https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49490#post-id-49490The code you posted has an indentation error on the last line: `n.append(x)` is indented an extra space compared to the previous line. There is no such error on the line `for i in ...`.Fri, 10 Jan 2020 17:57:20 +0100https://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/?comment=49490#post-id-49490