Two ways of calculating the degree sequence
So I'm trying to calculate the degree sequence of G, an undirected, connected simple graph. As far as I see it, there are two ways to do this. Iterate over all the vertices, or sum the rows of the adjacency matrix. So: def degree_sequence1(G): degs = [] for v in G.vertices(): degs.append(v.out_degree() + v.in_degree()) degs.sort() return degs def degree_sequence2(G): mat = gt.adjacency(G) degs = np.squeeze(np.asarray(mat.sum(axis=0))) degs.sort() return degs The first way definitely works. But when I try to use the second method, I find that even if I run this code on a connected network I get zeroes in my degree sequence. Which shouldn't be possible if the graph is connected. So I know that I'm understanding something wrong here. Can somebody point out where I went wrong here? Thanks! -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 13.02.2017 00:10, gogurt wrote:
So I'm trying to calculate the degree sequence of G, an undirected, connected simple graph. As far as I see it, there are two ways to do this. Iterate over all the vertices, or sum the rows of the adjacency matrix. So:
def degree_sequence1(G): degs = [] for v in G.vertices(): degs.append(v.out_degree() + v.in_degree()) degs.sort()
return degs
def degree_sequence2(G): mat = gt.adjacency(G) degs = np.squeeze(np.asarray(mat.sum(axis=0))) degs.sort()
return degs
The first way definitely works. But when I try to use the second method, I find that even if I run this code on a connected network I get zeroes in my degree sequence. Which shouldn't be possible if the graph is connected. So I know that I'm understanding something wrong here.
Can somebody point out where I went wrong here?
I tried the second function with a connected graph, and I did not see any zeros. Maybe it would help if you would provide a small but _complete_ example that shows the problem. Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
participants (2)
-
gogurt -
Tiago de Paula Peixoto