# [graph-tool] Two ways of calculating the degree sequence

Tiago de Paula Peixoto tiago at skewed.de
Mon Feb 20 19:51:39 CET 2017

```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 at skewed.de>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.skewed.de/pipermail/graph-tool/attachments/20170220/78a46835/attachment.asc>
```

More information about the graph-tool mailing list