# Attributes in the linegraph function

**URL:** <https://igraph.discourse.group/t/attributes-in-the-linegraph-function/1509>\
**Category:** Usage\
**Tags:** Python\
**Created:** [16 March 2023 13:09 UTC](https://igraph.discourse.group/t/attributes-in-the-linegraph-function/1509 "2023-03-16T13:09:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JanRhoKa](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/janrhoka/32/898_2.png) [@JanRhoKa](https://igraph.discourse.group/u/JanRhoKa)\
**Post date:** [16 March 2023 13:09 UTC](https://igraph.discourse.group/t/attributes-in-the-linegraph-function/1509/1 "2023-03-16T13:09:55Z")

</div>

I am currently looking into the differences between the `linegraph()` function compared to a one-node-projection in a bipartite graph and was wondering, if there was a way to conserve the edge attributes and move them to the vertices using the `igraph.GraphBase.linegraph()` function?

---

<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:** [16 March 2023 14:10 UTC](https://igraph.discourse.group/t/attributes-in-the-linegraph-function/1509/2 "2023-03-16T14:10:07Z")

</div>

You can copy the attributes manually with something like:

```python
lg = g.linegraph()
for attr in g.edge_attributes():
    lg.vs[attr] = g.es[attr]

```

You are welcome to submit a [feature request](https://github.com/igraph/igraph/issues/new/choose) to preserve vertex attributes, but please discuss realistic use cases in detail.

---

<div class="post-metadata">

**Author:** ![JanRhoKa](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/janrhoka/32/898_2.png) [@JanRhoKa](https://igraph.discourse.group/u/JanRhoKa)\
**Post date:** [16 March 2023 14:13 UTC](https://igraph.discourse.group/t/attributes-in-the-linegraph-function/1509/3 "2023-03-16T14:13:41Z")

</div>

Thank you very much for the input.

I wasn’t sure the indexing would be preserved. This should solve my problem and I will think a bit about the use cases.

---

<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:** [16 March 2023 14:16 UTC](https://igraph.discourse.group/t/attributes-in-the-linegraph-function/1509/4 "2023-03-16T14:16:32Z")

</div>

> [@JanRhoKa](#):
>
> I wasn’t sure the indexing would be preserved.

Good point. We will document that it is preserved.

---

<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:** [16 March 2023 14:22 UTC](https://igraph.discourse.group/t/attributes-in-the-linegraph-function/1509/5 "2023-03-16T14:22:12Z")

</div>

I should point out that when the python-igraph documentation is sparse on details, it’s usually worth checking the C documentation, which tends to give more details:

[https://igraph.org/c/html/latest/igraph-Operators.html#igraph\_linegraph](https://igraph.org/c/html/latest/igraph-Operators.html#igraph_linegraph)

I have now updated the python-igraph docs with this information.
