Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to change the Head of b (a NeighborhoodGraph) from Graph into List but Apply seems to fail. I start with a list of connected vertices:

a={1\[UndirectedEdge]1,2\[UndirectedEdge]2,1\[UndirectedEdge]3,3\[UndirectedEdge]3,
4\[UndirectedEdge]4,3\[UndirectedEdge]4,5\[UndirectedEdge]5,6\[UndirectedEdge]6,
6\[UndirectedEdge]2,7\[UndirectedEdge]7,8\[UndirectedEdge]5,8\[UndirectedEdge]8,
9\[UndirectedEdge]9,10\[UndirectedEdge]10,10\[UndirectedEdge]4};

I calculate the neighborhood graph of node 3. Its Head is Graph:

b=NeighborhoodGraph[a//Graph,3]
b//Head
(* ==> Graph *)

I use Apply to change the Head to List:

c=Apply[List,b];

However, the Head of c is still Graph:

c//Head
(* ==> Graph *)

My real question is how to access the list of edges in a NeighborhoodGraph.

share|improve this question
6  
As Graph[] is an atomic object, you cannot use Apply[] to extract the edges; instead, look up EdgeList[]. –  J. M. Jun 3 '13 at 18:23
    
Thanks! EdgeList seems to be very well hidden. I could not find it under See Also in Graph, NeighborhoodGraph SubGraph, nor in GraphConstruction, guide/GraphModifications... Which makes me especially grateful that you pointed it to me. –  Themis Jun 3 '13 at 19:18
    
It can be found on the Graph Representation and Properties guide page, a link to which can be found on the bottom of the Graph help page in the "Related guides" section. So, it wasn't really that far away. –  Sjoerd C. de Vries Jun 3 '13 at 21:35
add comment

1 Answer 1

Apply does not work on Graph objects because they are atomic (you can verify this using AtomQ).

You can use EdgeList to retrieve the edge list of any graph.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.