简体   繁体   中英

Python igraph: Count distinct edges in a weighted graph

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

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM