# Directed graphs and direction of edges

**URL:** <https://igraph.discourse.group/t/directed-graphs-and-direction-of-edges/169>\
**Category:** Usage\
**Tags:** Python\
**Created:** [3 April 2020 21:48 UTC](https://igraph.discourse.group/t/directed-graphs-and-direction-of-edges/169 "2020-04-03T21:48:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucasgac](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/lucasgac/32/178_2.png) [@lucasgac](https://igraph.discourse.group/u/lucasgac)\
**Post date:** [3 April 2020 21:48 UTC](https://igraph.discourse.group/t/directed-graphs-and-direction-of-edges/169/1 "2020-04-03T21:48:25Z")

</div>

How can i turn a directed graph into an undirected graph, being able to choose the direction of the edges? to\_directed gives an arbitrary direction to each edge, right?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [5 April 2020 09:22 UTC](https://igraph.discourse.group/t/directed-graphs-and-direction-of-edges/169/2 "2020-04-05T09:22:12Z")

</div>

Do you mean turn an undirected graph into a directed one? Based on what do you want to choose the edge directions?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [5 April 2020 09:42 UTC](https://igraph.discourse.group/t/directed-graphs-and-direction-of-edges/169/3 "2020-04-05T09:42:02Z")

</div>

For example, we can choose edge directions from low-index vertices to high-index vertices and thus obtain a directed acyclic graph:

```python
g=Graph.Erdos_Renyi(n=20,m=30)
dg=Graph([sorted(e) for e in g.get_edgelist()], directed=True)
dg.vs["label"]=range(dg.vcount())
plot(dg, layout=dg.layout_sugiyama())
dg.is_dag()

```

 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/53216b72e3b4124f0c247753de1764a203484f5a.png)
