[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [igraph] Merging two graphs

**From**: |
Tamas Nepusz |

**Subject**: |
Re: [igraph] Merging two graphs |

**Date**: |
Thu, 6 Oct 2016 11:16:43 +0200 |

Hello!
Unfortunately the Python interface is currently lacking such a
function, but you can work around this if the graphs involved have the
same number of vertices. Basically, what you need to do is to use the
permute_vertices() method on one of your graphs and permute its
vertices such that the IDs will be in the same order as in the
original graph, then use union(). If the ID sets of the two graphs are
different (i.e. only partially overlapping), then it is a bit more
complicated because first you need to extend both graphs with isolated
vertices corresponding to the "missing" IDs so they have the same ID
set, and then call permute_vertices() on one of them, and then finally
call union().
Attached is a Python script containing a union_by_attr() function that
does what you probably need. It is incomplete because it does not copy
any other attributes from the original graphs to the union (i.e.
attributes are lost because union() does not support attribute
unification yet). Copying the vertex attributes should be
straightforward, though.
T.
On Thu, Oct 6, 2016 at 9:32 AM, Kuu <address@hidden> wrote:
>* Hello!*
>
>* I have two graphs and each of them have vertices with the "id" attribute.*
>
>* I want to merge both of them by this attribute but I cannot find a method*
>* for doing so (I'm on Python btw). I saw union and compose methods, but they*
>* seem to join vertices by index, I'm not sure about this as it is not*
>* explained in the docs, but my tests seem to point that.*
>
>* So my questions: how do compose/union methods work? Is there a way of doing*
>* the merge by id/name attribute instead of the vertex index?*
>
>* Thank you*
>
>* Regards,*
>* Javier*
>
>
>* _______________________________________________*
>* igraph-help mailing list*
>* address@hidden*
>* https://lists.nongnu.org/mailman/listinfo/igraph-help*
>

**
**`merge_graphs.py`

*Description:* Text Data