# Graph generation from a non-paired edge list

The elements in

e = {{6414, 6598, 6927}, {7, 1035, 2382, 6927}, …}


are the graph nodes; for example, {6414,6598,6927} is equivalent to the two pairs, {6414, 6598} and {6598, 6927}. I wanted to know if a Graph object can take non-paired edge list format as in the original e. If not I can convert each edge element into a pair-format by using Partition, i.e. Partition[e, 2, 1].

• @Szabolcs is correct. I now see that your matrix e is (likely) not an adjacency list. So what does your list e represent? Can you craft a teeny, illustrative example? What does 6414 in the matrix represent? – David G. Stork Jun 10 '15 at 16:47

 WeightedAdjacencyGraph[mywts = Table[RandomReal[], {4}, {4}],
VertexLabels -> "Name",
EdgeLabels ->
Table[Rule[EdgeList[mygraph][[i]], Flatten[mywts][[i]]], {i, 16}]]


Thread is useful for converting this format to a simple edge list.

Example:

Thread[ 1 <-> {2,3,4} ]

(* {1 <-> 2, 1 <-> 3, 1 <-> 4} *)


Using this idea, you could do

Graph@Catenate[Thread[First[#] <-> Rest[#]] & /@ e]


For Mathematica versions earlier than 10, use Flatten[..., 1] in place of Catenate[...].

e = {{6414, 6598, 6927}, {7, 1035, 2382, 6927}};


### BlockMap

Graph[Join @@ (BlockMap[DirectedEdge @@ # &, #, 2, 1] & /@ e),
VertexShapeFunction -> "Name"]


### Partition

Using the undocumented 6-argument form of Partition:

Graph[Join @@ (Partition[#, 2, 1, {1, -1}, {}, DirectedEdge] & /@ e),
VertexShapeFunction -> "Name"]


same picture

### PathGraph + GraphUnion

 GraphUnion @@ (PathGraph[#, DirectedEdges -> True] & /@ e);
SetProperty[%, VertexShapeFunction -> "Name"]