Hi,
Please tell me what went wrong in the following code:
g=XGraph(multiedges=false,selfloops=true)
#I have added some edges
c=networkx.number_connected_components(obj.g) # Gave the value 118
k=networkx.connected_components(g)
for i in k:
d=diameter(i)
But I get the following error.
File "C:\Python25\Lib\site-packages\networkx\distance.py", line 60, in diameter
e=eccentricity(G,with_labels=True)
File "C:\Python25\Lib\site-packages\networkx\distance.py", line 28, in eccentricity
nodes=G.nodes()
AttributeError: 'list' object has no attribute 'nodes'
Another question, is there any facility in networkx to check whether
a node is included in any cycle. Is your cycle_graph() function can do
any purpose here..
THanks and regards,
deepa
Use networkx.connected_component_subgraphs here
> for i in k:
> d=diameter(i)
>
> But I get the following error.
> File "C:\Python25\Lib\site-packages\networkx\distance.py", line 60, in
> diameter
> e=eccentricity(G,with_labels=True)
> File "C:\Python25\Lib\site-packages\networkx\distance.py", line 28, in
> eccentricity
> nodes=G.nodes()
> AttributeError: 'list' object has no attribute 'nodes'
>
>
> Another question, is there any facility in networkx to check whether
> a node is included in any cycle. Is your cycle_graph() function can do
> any purpose here..
There are no cycle detection or counting algorithms. If you write
some we'd be glad to include them.
Aric
Iam trying to write the code to find out cycles.
One more doubt regarding the diameter like:
I have a graph of about 700 nodes and
networkx.number_connected_components gave the value 16.
This means that there are 16 distinct connected components.
I want to find out the diameter for each of the components
and then took its average.
I used as u said in the previous reply..But the results i
got was amazing and iam doubted whether i have used it in the right way..
Here is the code
k=networkx.connected_component_subgraphs(obj.g)
for i in k:
print "\nNodes in component :",i.nodes() #line 2
p=p+diameter(i)
Line 2 give lists which consists of only 2 or 0 nodes. Iam sure the graph consists
of connected components which will have more nodes than this.
Pls help if i went wrong anywhere...
Can you provide this graph...or a smaller graph which demonstrates the
same problem? I am in agreement that a connected component should not
have 0 nodes.
Chris