Reputation: 13520
I am using python igraph to create a weighted graph from input files. The point is that I need the number of distinct edges (since this is a weighted graph). I know that
graph.ecount()
does not take this into account. I can do it reading the file itself and count number of distinct edges but I wanted to know if the igraph itself has a function or an attribute I can set for ecount to count distinct number of edges. Note that I use the following line of code to create my graphs:
graph= Graph.Read_Ncol(file, names=True, weights="if_present", directed=True)
Thanks
Upvotes: 2
Views: 973
Reputation: 48101
I'm not sure why the weights matter at all here - Graph.Read_Ncol
will simply store the weights as edge attributes and they are not taken into account by g.ecount()
. The only thing that could matter here is that Graph.Read_Ncol
creates a multigraph for you for some reason (in which case there could be multiple edges between the same pair of vertices). You can get rid of multiple edges (but keep the loop edges) with g.simplify(loops=False)
and then you can call g.ecount()
.
Upvotes: 2