Viewing Subgraph in Networkx

96 views
Skip to first unread message

Subhabrata Banerjee

unread,
Jan 13, 2013, 3:04:07 PM1/13/13
to networkx...@googlegroups.com
Dear Group,

I have two questions, if I take a subseries of the matrix as in eigenvalue here,
provided I have one graph of the full form in G, how may I show it, as if I do the nx.draw(G) it takes only the original graph.

>>> import numpy
>>> import networkx as nx
>>> import matplotlib.pyplot as plt
>>> G=nx.Graph()
>>> G.add_edges_from([(1,2),(1,3),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8)])
>>> L =nx.laplacian(G)
>>> print L
[[ 7. -1. -1. -1. -1. -1. -1. -1.]
 [-1.  1.  0.  0.  0.  0.  0.  0.]
 [-1.  0.  1.  0.  0.  0.  0.  0.]
 [-1.  0.  0.  1.  0.  0.  0.  0.]
 [-1.  0.  0.  0.  1.  0.  0.  0.]
 [-1.  0.  0.  0.  0.  1.  0.  0.]
 [-1.  0.  0.  0.  0.  0.  1.  0.]
 [-1.  0.  0.  0.  0.  0.  0.  1.]]
>>> print numpy.linalg.eigvals(L)
[  8.00000000e+00   2.22044605e-16   1.00000000e+00   1.00000000e+00
   1.00000000e+00   1.00000000e+00   1.00000000e+00   1.00000000e+00]

for more than 1000 nodes it is coming too slow on Windows 7 machine with 3GB RAM.

If any one of the learned members can help.

Apology for any indentation error etc.

Thanking all in Advance,

Regards,
Subhabrata Banerjee.

Aric Hagberg

unread,
Jan 13, 2013, 3:38:13 PM1/13/13
to networkx...@googlegroups.com
If you don't need all of the eigenvalues you can try the scipy sparse
eigenvalue solver
http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.eigsh.html
instead of the numpy.linalg.eigvals() solver.

Aric

Subhabrata Banerjee

unread,
Jan 13, 2013, 3:51:13 PM1/13/13
to networkx...@googlegroups.com
Thanks Aric. But Scipy does not seem to have sparse.
>>> vals, vecs = sp.sparse.linalg.eigsh(id, k=6)

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    vals, vecs = sp.sparse.linalg.eigsh(id, k=6)
AttributeError: 'module' object has no attribute 'sparse'
>>>

And my question was not the values but I wanted to view in plotting graph as we can see it in nx.subgraph(

Regards,
Subhabrata Banerjee.




--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.




--
Sree Subhabrata Banerjee
PDF(2007-2010)[IISc, Bangalore]
Call:09873237945
Member, IEEE(USA), ACM(USA).
 

Aric Hagberg

unread,
Jan 13, 2013, 4:00:32 PM1/13/13
to networkx...@googlegroups.com
On Sun, Jan 13, 2013 at 1:51 PM, Subhabrata Banerjee
<subhaba...@gmail.com> wrote:
>
>>>>


Maybe your scipy installation isn't complete?


In [1]: from scipy.sparse import linalg

In [2]: linalg.e
linalg.eigen linalg.eigs linalg.eigsh

In [2]: linalg.eigsh?


Can you be more specific about your drawing question?

Aric

Subhabrata Banerjee

unread,
Jan 13, 2013, 4:19:28 PM1/13/13
to networkx...@googlegroups.com
Hi Eric,
This is fine.
>>> linalg.eigsh
<function eigsh at 0x038E3BB0>

My drawing question is,
Suppose I have a graph like,
>>> g = nx.DiGraph()
>>> g.add_path(['A','B','C',])
>>> g.add_path(['X','Y','Z',])

I can draw it and see the plotting(provided I imported "import matplotlib.pyplot as plt")
with,
>>> nx.draw(g)
>>> plt.show()

and I can also see the
>>> u = g.to_undirected()
>>> nodes = nx.shortest_path(u,'B').keys()
>>> s = g.subgraph(nodes)
>>> s = g.subgraph(nx.shortest_path(g.to_undirected(),'B'))
>>> nx.draw(s)
>>>plt.show()

In the same way, I like to see the drawing and plotting of numpy.linalg.eigvals(L) which is a subset of L as a subgraph,
that is to say first my graph -G is drawn and then my subgraph is drawn. Getting values I am facing no problem. Numpy is going fine.

Regards,
Subhabrata Banerjee.
Reply all
Reply to author
Forward
0 new messages