[Python] Why does VertexClsutering.membership returns a copy?

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    Working with igraph in a project, we encounter serious timing issues. Running cProfile on the worst function, we realize that this code takes a lot of time:

    [ partition.membership[x.index] if x.index < len(partition.membership) else -1 for x in G.vs ]


    where G is a Graph.

    Looking at the documentation, it appears that membership is a property returning a copy of the membership:

    @property
    def membership(self):
    """Returns the membership vector."""
    return self._membership[:]


    Is there a reason for returning an explicit copy and not just self._membership?

    Continue reading...

Compartilhe esta Página