# Edgelist representation as array

**URL:** <https://discourse.julialang.org/t/edgelist-representation-as-array/49960>\
**Category:** Graphs\
**Tags:** lightgraphs\
**Created:** [November 11, 2020, 1:05am UTC](https://discourse.julialang.org/t/edgelist-representation-as-array/49960 "2020-11-11T01:05:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [November 11, 2020, 1:05am UTC](https://discourse.julialang.org/t/edgelist-representation-as-array/49960/1 "2020-11-11T01:05:07Z")

</div>

I am wanting to get an edgelist from my graph that can then be used as a coordinate in 2D.

```julia
using LightGraphs
A = [
0 1 1
1 0 1
1 1 0
]

G = Graph(A)
EL = collect(edges(G))

```

How can the edge list EL be converted to an array EL2, where EL2 just contains the row and column index of an undirected edge?

```julia
EL2 = [
1 2
1 3
2 3
] 

```

Thank you for any help on this 🙂

---

<div class="post-metadata">

**Author:** ![pjgorski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjgorski/32/4802_2.png) [@pjgorski](https://discourse.julialang.org/u/pjgorski)\
**Post date:** [September 27, 2022, 11:39am UTC](https://discourse.julialang.org/t/edgelist-representation-as-array/49960/2 "2022-09-27T11:39:15Z")

</div>

I guess you can work on an adjacency matrix and find indices of non-zero elements, e.g.:

```julia
using LinearAlgebra
inds = findall(triu(A,1) .> 0)

```

(`LinearAlgebra.triu` is in the case of undirected graph.)  
Then to get the Array, you can do for instance:

```julia
a = [ind.I for ind in inds]
hcat(collect.(a)...)'

```
